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

Communicate Using UDP

Problem

You need to send data between two computers on a network using a User Datagram Protocol (UDP) stream.

Solution

Use the UdpClient class, and use two threads: one to send data, and the other to receive it.

Discussion

UDP is a connectionless protocol that doesn’t include any flow control or error checking. Unlike TCP, UDP shouldn’t be used where communication is critical. However, because of its lower overhead, UDP is often used for "chatty" applications where it’s acceptable to lose some messages. For example, imagine you want to create a network where individual clients send information about the current temperature at their location to a server every few minutes. You might use UDP in this case because the communication ...

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