views:

126

answers:

2

I am using creating a server/client style program, and it uses tcp connections.

Now, the server is like this, but it will only listen until it has received its one request. My issue lies in the fact that it only listens till it receives the one message, then closes. The bigger issue, though, is the lag, it will not let me interact with the form in any way until it closes the connection. Is there a way to make it "passively" listen, for lack of a better word? I do not want it to take up tons of cpu.

Thanks for the help!

This is in vb.net.

+1  A: 

In Windows, events like key presses, mouse clicks and movements, etc, are sent as events (messages) to a thread dedicated to processing them. If that thread takes a long time to process a message (as in waiting for a TCP request to come in), the thread is said to "block" until that task completes, essentially blocking your entire user interface.

You want to setup a thread separate from the one running your form to handle the TCP listening. This tutorial on threading in Vb.Net should get you headed down the right path.

Eric J.
Threading did it. Thanks!!!!!
Cyclone
A: 

Have a look at the TcpListener class, also check the code shown for the Pending method.

You're really better off using threads to handle all of this, as you want your UI thread to stay available to keep your UI responsive.

Timothy Walters