port number not matching
Hi,
In TCP client server,if I explicitly bind client port for connecting with server at Client side it is showing correct port.However on server when I accept connection from client the port number of client is not matching. Client is running on windows and I am using htos(portnum) before binding. Server is running on Linux and ntohs() is used before displaying port. on both sides netstat is showing different port numbers. Please give the solution if u understand the problem Thanks for reading... |
Moved: This thread is more suitable in Programming and has been moved accordingly to help your question get the exposure it deserves.
|
When you indicated that you are binding the client's socket to a port, do you mean that you are connecting to the server? It is not typical for the client to bind() to a port, but I suppose it could be done. Either way the client will still need to connect() to the server.
When I tested, my client has an ephemeral port assigned to it, and it is connected to the server. I can verify this using netstat -atp. On the server side (different machine), I can again verify the connection using netstat. The output is the converse of what is shown on the client side. For example, on the client side: Code:
tcp 0 0 clienthost:59985 serverhost:9000 ESTABLISHED 29610/client Code:
tcp 0 0 serverhost:9000 clienthost:59985 ESTABLISHED 7328/server P.S. I just retested, having my client bind() specifically to a port number that I chose at random. Sure enough, netstat reports, on both the client-side and server-side, that my client is using said port. If your client is using bind(), make sure that 1) you are using an unused port number, and 2) you verify that bind() succeeded. |
yes bind is verified success, but i m not getting the converse on server and client as shown above...
thanks |
Is there a NAT between the client and server?
|
client,server are on different networks and I guess NAT is being used in between.
|
All times are GMT -5. The time now is 12:07 PM. |