[C#] More TCP problems!

Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
Been playing around with async network streaming as Reezer suggested. I have a simple server that runs as a console app and displays any messages that are sent to it.

It works brilliantly when I run it locally, but when it's across the network, the server doesn't pick anything up, despite Ethereal showing incoming TCP packets.

Here's the relevant code:
Code:
public void Start()
{
	Console.WriteLine("Server starting...");

	m_Listener.Start();
	m_IsRunning = true;
	m_IsStopRequested = false;

	WaitCallback callback = Listen;
	ThreadPool.QueueUserWorkItem(callback);
}

...

private void Listen(object state)
{
	Console.WriteLine("Listening for connections on port {0}...", m_Port);
	Console.WriteLine();
	while (!m_IsStopRequested)
	{
		Socket socket = m_Listener.AcceptSocket();
		ClientHandler handler = new ClientHandler(socket);
		handler.StartRead();
	}

	Console.WriteLine("Server stopped.");
	m_IsRunning = false;
	m_IsStopRequested = false;
}

I've tried stepping through the code, and it seems to hang at the m_Listener.AcceptSocket() method call, implying that it can't detect any incoming connections.

Can anyone shead any light on this?
 
edit: Sorry, I was being an idiot, I was initialising the TcpListener with the IP 127.0.0.1 rather than IPAddress.Any :o

Works now, thanks for the replies :)
 
Last edited:
Back
Top Bottom