I'm trying to do a simple server with the TcpListener class, and I'm using multithreading to handle the accept()'ing. Of course, that's sort of a hangover from C++ Winsock habits (I never could get a handle on asychronous sockets).
Anyway, my code looks like this:
where startClick() is generated when the user clicks a button on the form to begin the server.Code:void startClick(object sender, System.EventArgs e) { server.Start(); Thread thread = new Thread(new ThreadStart(Listen)); } public void Listen() { Socket accept; while(true) { accept = server.AcceptSocket(); listBox.Items.Add(accept.RemoteEndPoint); } }
For some reason the thread is never generated, and the Listen() function is never called.
Also, is working with asynchronous sockets any easier in C# if so, maybe I should just do that...