If the following code is incorrect or you do not understand it, contact QQ: 41305987.
Code
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Using system. net. Sockets;
Using system. net;
Using system. Threading;
Namespace point_talk_to_face
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private thread th;
Udpclient UDP, udp2;
Bool L = true;
Private void textbox2_textchanged (Object sender, eventargs E)
{
}
Private void form1_load (Object sender, eventargs E)
{
System. Windows. Forms. Control. checkforillegalcrossthreadcils = false;
Th = new thread (New threadstart (Listen ));
Th. Start ();
}
Private void button#click (Object sender, eventargs E)
{
/**************************** Send ********* **************************************** ***/
Udp2. = new udpclient (textbox3.text, 9999 );
Byte [] DATA = encoding. ASCII. getbytes (textbox2.text );
Udp2.send (data, data. Length );
Textbox1.appendtext ("to me" + textbox3.text + ":" + textbox2.text + "\ n ");
Udp2.close ();
This. textbox2.clear ();
Textbox2.focus ();
/********************************** Send **** **************************************** *********/
}
Private void listen ()
{
/*************************************** ********************************** ****************/
UDP = new udpclient (9999 );
Ipendpoint remoteiep = new ipendpoint (ipaddresses. Any, 9999 );
While (l)
{
Try
{
Byte [] DATA = UDP. Receive (ref remoteiep );
If (data. length> 0)
{
String word = encoding. ASCII. getstring (data );
Label1.text = remoteiep. Address. tostring ();
Label2.text = remoteiep. Port. tostring ();
Textbox1.appendtext (label1.text + "to me:" + word. tostring () + "\ n ");
}
Else
{
}
}
Catch (exception ex)
{
// Textbox1.appendtext (ex. Message );
// MessageBox. Show (ex. Message. tostring ());
}
}
/*************************************** *********************************** ************************/
}
Private void textbox1_textchanged (Object sender, eventargs E)
{
}
Private void close (Object sender, formclosingeventargs E)
{
Th. Abort ();
L = false;
UDP. Close ();
}
Private void form=formclosed (Object sender, formclosedeventargs E)
{
}
}
}