user1692342
user1692342

Reputation: 5237

Packet forwarded to destination, but application doesnt receive

I am trying to run a simple client-server program on my machine. It works fine if both client and server are on the same system. But if the client is on another system and server is running on mine, it doesnt work. It works the other way round. When I did a netstat command it shows from the client side SYN_SENT, but the server still shows LISTENING. Wireshark confirms that it received the message from the client, but still the messsage doesnt reach the server.

I am running on Windows XP.

This is the client side netstat

TCP    si-rohitp:5002         10.221.40.62:5003      SYN_SENT

This is server side netstat

TCP    127.0.0.1:1045         0.0.0.0:0              LISTENING
 TCP    127.0.0.1:5152         0.0.0.0:0              LISTENING

Upvotes: 0

Views: 86

Answers (2)

Mattias
Mattias

Reputation: 1391

Your server program is only listening to localhost. When doing socket programing your program is not only listing to a special port it is also listening to a specific IP address. If a program listens to local host that will result i a program that will never get connection for outside of your computer. Rewrite the code in the server program to listen to it's IP address. You can lookup the current IP address of the computer that the server program is running on with help of the network function.

If your program is not only goning to use socket for computer internal communication, then you should always bind to the real IP address. If your program is only going to use sockets for internal communication you should always bind to local host because of lesser security fotprint.

If you don't have access to the source code of the server program and there are no ways of customizeing the behavior of the sever program your screwed.

Upvotes: 1

xaxxon
xaxxon

Reputation: 19771

when you call bind, you need to specify which addresses to bind your socket to. If you pass in INADDR_ANY, it will bind to all devices, so you'll be able to get connections from local and remote hosts.

http://man7.org/linux/man-pages/man7/ip.7.html

Upvotes: 1

Related Questions