I’m working on a simple hello world TCP/IP client server app in C# and am unable to get my client to connect. Can anyone offer any additional troubleshooting steps? I’m starting to run out of ideas…
Here are the relevant sections of code:
server:
Console.Out.WriteLine('About to bind address'); IPAddress ipAd = IPAddress.Parse('127.0.0.1'); Console.Out.WriteLine('Choose a port to bind...'); String port = Console.In.ReadLine(); int iPort = Int32.Parse(port); TcpListener myList = new TcpListener(ipAd, iPort); myList.Start(); Console.WriteLine('The server is running at: '+myList.LocalEndpoint); Console.WriteLine('Waiting for a connection.....'); Socket s = myList.AcceptSocket(); Console.WriteLine('Connection accepted from ' + s.RemoteEndPoint);
client:
Console.Out.WriteLine('enter address: '); string address = Console.In.ReadLine(); Console.Out.WriteLine('enter port: '); int port = Convert.ToInt32(Console.In.ReadLine()); TcpClient tcpclnt = new TcpClient(); Console.WriteLine('Connecting.....'); Console.Out.WriteLine('Address: ' + address + ':' + port); tcpclnt.Connect(address, port);
I am able to ping the server from the client machine, however I am unable to telnet to the server using the bound port. I’ve tried a variety of ports (a few in the low 8000s and a few up around 40000). I have disable windows firewall on both systems. The systems are connected to a router which is not on the internet. I’ve tried with and without port forwarding set to forward incoming requests on the given port to the server machine with no effect.
The only exception that I’ve been able to trap is thrown by the client:
No connection could be made because the target machine actively refuses it.
I checked for an InnerException but it seems that there are none – that is the base exception. Could that be right?
Not sure what else I should be looking at – any additional troubleshooting steps would be helpful.
Thanks!
The code above is listening to request coming from the loopback address. This will effectively only listen to connection on that network, and that network only includes your machine.
Have you tried listening to the address bound to the network from which the connection should be coming? On a local network it should be something like 192.168.x.x or 10.x.x.x