02-03-2013 03:45 PM
02-03-2013 05:28 PM
4 weeks ago
This exception message says you're trying to connect to the same host ( 127.0.0.1 ), while you're stating that your server is running on a different host. This 127.0.0.1 represents a 'loopback' . It allows the computer to communicate with itself via network protocol .
Dns.GetHostEntry(IPAddress.Loopback).HostName returns the host name of your machine. When you pass a host name to TcpClient , it will resolve it to one or more IP addresses using Dns.GetHostAddresses(hostName) . This includes the public and local IP addresses of your machine (e.g. 192.168.12.10), but not 127.0.0.1 (loopback address). So your client is trying to connect to any of the non-loopback addresses of your machine, while your server is listening only on the loopback address . So, no connection can be established. The solution to this problem is that connect to the same end point your server is listening on.