O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create a Multithreaded TCP Network Server

Problem

You want to create a TCP server that can simultaneously handle multiple TCP clients.

Solution

Every time a new client connects, start a new thread to handle the request.

Discussion

A single TCP endpoint (IP address and port) can serve multiple connections. In fact, the operating system takes care of most of the work for you. All you need to do is launch a worker object on the server that will handle the connection on a new thread.

For example, consider the basic TCP client and server classes shown in recipe Communicate Using TCP. You can convert the server into a multithreaded server that supports multiple simultaneous connections quite easily. First create a class that will interact with an individual ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required