This sample illustrates using the UdpClient class to create a chat client.
This sample is a functional chat client. It uses the user datagram protocol (UDP) to send and receive chat messages with other users that are also using the client. The program illustrates use of the UdpClient class and threading.
THe UdpClient object is initialized with a constructor call that sets the port that the object will listen on. The object then joins a Multicast group. This code can be found in the Initialize function of the sample code.
Once initialized, the UdpClient listens for incoming messages with the Receive function, which can be found in the Listener function of the sample code. The Receive function returns an array of bytes, containing the data sent. This data can be converted into a string with the ASCII object GetString function.
Sending data is also easy. The UdpClient class includes a function called Send, which sends out a byte array to every class that is listening on the Multicast group.
The sample source is found in sscli\samples\howto\net\udpchat.
The source file is:
The build output location is %TARGETCOMPLUS%\samples\howto\net\udpchat. The output file is an executable assembly named udpchat.exe.
All samples are built from the buildall script.
You can also build all the
samples by switching to the root of the sample directory, sscli\samples, and typing
build -c.
You can build this specific sample by switching to the sample directory and typing
build -c.
These steps require that the Shared Source CLI (SSCLI) be already built and functional.
clix udpchat.exe
Copyright (c) 2002 Microsoft Corporation. All rights reserved.