I am writing a simple C# tcp client and server program. The server will eventually be on a different machine but now I am just testing on the same machine. I am getting an exception error "Only one usage of each socket address (protocol/network address/port) is normally permitted" when I create my TcpClient using the ip address. But it works if I use "localhost" instead of ip address. I get the ip address from ipconfig. I also try having the server running on a different machine and my TcpClient gets the same exception when I specify the remote machine's ip address. How do I make the connection using ip address? thanks.
Below is the code where I create the TcpClient
IPAddress ipaddr = IPAddress.Parse("192.168.128.100");
int port = 3000;
int tries = 0;
client = null;
while (tries < 6) // try for 3 seconds
{
try
{
tries++;
IPEndPoint ipEndpt = new IPEndPoint(ipaddr, port);
client = new TcpClient(ipEndpt);
}
catch (Exception ex)
{
client = null;
Thread.Sleep(500);
}
}