LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   port number not matching (https://www.linuxquestions.org/questions/programming-9/port-number-not-matching-871629/)

pawan_linux 03-29-2011 01:31 AM

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...

jschiwal 03-29-2011 05:36 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your question get the exposure it deserves.

dwhitney67 03-29-2011 05:53 AM

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
On the server side:
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.

pawan_linux 03-29-2011 01:16 PM

yes bind is verified success, but i m not getting the converse on server and client as shown above...

thanks

TimothyEBaldwin 03-30-2011 02:42 AM

Is there a NAT between the client and server?

pawan_linux 03-31-2011 12:49 AM

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.