I’ve just spent two days on this. This is run in the game engine Unity3D, but that shouldn’t make a difference. These two lines ALWAYS fail:
TcpClient client = new TcpClient();
client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15219));
The error I get is:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0
at StreamIn.Connect (System.String server, System.String message) [0x00011] in C:\XXX\StreamIn.cs:41
UnityEngine.Debug:Log(Object)
StreamIn:uPrint(String) (at Assets/StreamIn.cs:27)
StreamIn:Connect(String, String) (at Assets/StreamIn.cs:77)
StreamIn:Start() (at Assets/StreamIn.cs:18)
I’ve tried everything, including changing my firewall settings and disabling the firewall.
I get the same error with a dummy IP address.
If I try port 80 instead of 15219, the Unity editor freezes. (I do have a web server running.)
Am I missing something obvious? Or not obvious?
I always find it useful to sanity check these things with a different network tool outside of my .NET code. I think hercules is great for this as you can easily open up a tcp server for you app to connect to, and/or test a connection from a client perspective.