11.10. Communicate Using TCP

Problem

You need to send data between two computers on a network using a TCP/IP connection.

Solution

One computer (the server) must begin listening using the System.Net.Sockets.TcpListener class. Another computer (the client) connects to it using the System.Net.Sockets.TcpClient class. Once a connection is established, both computers can communicate using the System.Net.Sockets.NetworkStream class.

How It Works

TCP is a reliable, connection-oriented protocol that allows two computers to communicate over a network. It provides built-in flow control, sequencing, and error handling, which make it reliable and easy to program.

To create a TCP connection, one computer must act as the server and start listening on a specific ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.