int port = 44344;
var thread = new Thread(
() =>
{
TcpListener listener = null;
try
{
listener = new TcpListener(IPAddress.Any, port);
listener.Start();
while (true)
{
var client = listener.AcceptTcpClient();
}
}
catch (ThreadInterruptedException)
{ }
if (listener != null)
listener.Stop();
});
thread.Start();
Thread.Sleep(TimeSpan.FromSeconds(1));
var socket = new Socket(SocketType.Stream, ProtocolType.IP);
socket.Connect("localhost", port);
This code fails on the last line with "No connection could be made because the target machine actively refused it" exception, when running on my PC. Any ideas what can be the reason and how to fix it?
ProtocolType.Tcp? - Eser