i have a question about sockets/clients….
I just finished writing a client server program in C#. I was wondering, how do you connect to computers that have a different IP address. For instance, if i want to run a client and server seperately on two different machines, loopback (or using the localhost) won’t allow for this….
Not too familiar with networking, any help would be greatly appreciated.. here is my code on the client side which deals with loopback:
TcpClient client = new TcpClient();
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888);
You just need to know the IP address of the server, and specify that in the client side code.
You can get your IP by typing
ipconfig /allon the command prompt. Note that this will only give you the connection to the local network.If you’re trying to do this over the Internet, you’ll need to use a service that finds your WAN (wide-area network) IP address. You can google for how to do that, as there is no “standard” service to do this.
If you have a router, you’ll need to forward a port to the machine your service is running on. Look up Network Address Translation, and check out the documentation for your router, or call tech support. Or google “how do I forward ports?”.
Once you have your network set up, and know all your connection info, and assuming you are using
TcpListener:TcpListenerwithIpAddress.Any. Specify any port number you like, that isn’t already in use (8888).IPAddress.Parse("127.0.0.1")and8888with the port and address of the server.