Tom Arad
Tom Arad

Reputation: 3

Networking in c#,not lan

I wanted to learn how networking in c# works, so I learned how to use TCP server and clients. The only problem is that it's working only if both computers are connected to the same network..

How can I make them communicate even if they aren't?

Upvotes: 0

Views: 296

Answers (2)

Shane Wealti
Shane Wealti

Reputation: 2342

TCP/IP sockets should work between any two end points as long as there is a route between them. If there is no route between them then you are talking about a case where there are two separate disconnected networks. In that case you will need something to bridge the two networks.

If you are using TCP/IP server/client communication and the computers are on different networks that has a route connecting them and they cannot communicate then you should look at firewall settings and other network settings to make sure TCP/IP packets from one network are able to reach the other network.

Make sure you are using the correct IP address when the client tries to connect to the server. If you have a server at IP address 10.0.0.5 listening on port 4823 try to telnet to that IP address from the client using the server IP address 10.0.0.5 and port 4823. If it connects that usually means that you have things set up right.

From a command prompt: telnet 10.0.0.5 4823

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Communication in TCP is done with IP addresses. So even if the client and the server are not on the same network if you specify the IP address of the server, the client will be able to communicate with it (assuming of course the network that the client resides on is configured properly and knows how to reach the server's network). You could also use the DNS service and provide the FQDN of the server instead of an IP address. The DNS server on the client network will resolve the server's FQDN to an IP address.

Upvotes: 0

Related Questions