AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Make a chat client with UDPClient?

This sample illustrates using the UDPClient class to create a chat client.

This sample is a complete and fully functional chat client. It uses UDP to send and receive chat messages with other users that are also using the client. The program illustrates many important Microsoft .NET Framework concepts, but the most important (for this example) is the use of the UDPClient class.

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 just as easy. The UDPClient includes a function called Send which sends out a byte array to every class that is listening on the Multicast group.

To run this sample, you will need two machines:

  1. Machine A: Compile and run chat.exe
  2. Machine B: Compile and run chat.exe
  3. Machine A: Type text and it will appear on Machine B
  4. Machine B: Type text and it will appear on Machine A

Example

VB Chat.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\net\TCPUDP\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.