Using the UdpClient class
This is the test code I wrote, for reference ~
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.Globalization;
Using System.Net;
Using System.Net.Sockets;
Using System.Threading;
Using System.Text;
Namespace Udpwintest
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private System.Windows.Forms.Button btnstart;
Private System.Windows.Forms.Button Btnjoin;
Private System.Windows.Forms.TextBox Txtserverip;
Private System.Windows.Forms.Button button1;
Private System.Windows.Forms.TextBox txtmsgsend;
Private System.Windows.Forms.TextBox Txtmessagemain;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
private static UdpClient m_client;
private static int listenerport = 80;
private static int senderport = 80;
private static int localport;
private static int remoteport;
Private Thread t = null;
Private Thread t2 = null;
Public Form1 ()
{
InitializeComponent ();
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.btnstart = new System.Windows.Forms.Button ();
This.btnjoin = new System.Windows.Forms.Button ();
This.txtserverip = new System.Windows.Forms.TextBox ();
This.txtmessagemain = new System.Windows.Forms.TextBox ();
This.txtmsgsend = new System.Windows.Forms.TextBox ();
This.button1 = new System.Windows.Forms.Button ();
This.btnend = new System.Windows.Forms.Button ();
This.btnclose = new System.Windows.Forms.Button ();
This. SuspendLayout ();
//
Btnstart
//
This.btnStart.Location = new System.Drawing.Point (16, 16);
This.btnStart.Name = "Btnstart";
This.btnStart.TabIndex = 0;
This.btnStart.Text = "Start";
This.btnStart.Click + = new System.EventHandler (This.btnstart_click);
//
Btnjoin
//
This.btnJoin.Location = new System.Drawing.Point (408, 16);
This.btnJoin.Name = "Btnjoin";
This.btnJoin.TabIndex = 1;
This.btnJoin.Text = "Join";
This.btnJoin.Click + = new System.EventHandler (This.btnjoin_click);
//
Txtserverip
//
This.txtServerIP.Location = new System.Drawing.Point (304, 16);
This.txtServerIP.Name = "Txtserverip";
This.txtServerIP.Size = new System.Drawing.Size (96, 21);
This.txtServerIP.TabIndex = 2;
This.txtServerIP.Text = "10.89.58.220";
//
Txtmessagemain
//
This.txtMessageMain.Location = new System.Drawing.Point (16, 48);
This.txtMessageMain.Multiline = true;
This.txtMessageMain.Name = "Txtmessagemain";
This.txtMessageMain.Size = new System.Drawing.Size (464, 184);
This.txtMessageMain.TabIndex = 3;
This.txtMessageMain.Text = "";
//
Txtmsgsend
//
This.txtMsgSend.Location = new System.Drawing.Point (16, 240);
This.txtMsgSend.Name = "Txtmsgsend";
This.txtMsgSend.Size = new System.Drawing.Size (384, 21);
This.txtMsgSend.TabIndex = 4;
This.txtMsgSend.Text = "";
//
Button1
//
This.button1.Location = new System.Drawing.Point (408, 240);
This.button1.Name = "Button1";
This.button1.TabIndex = 5;
This.button1.Text = "Send";
This.button1.Click + = new System.EventHandler (this. Send_click);
//
Btnend
//
This.btnEnd.Location = new System.Drawing.Point (112, 16);
This.btnEnd.Name = "Btnend";
This.btnEnd.TabIndex = 6;
This.btnEnd.Text = "End";
This.btnEnd.Click + = new System.EventHandler (This.btnend_click);
//
Btnclose
//
This.btnClose.Location = new System.Drawing.Point (208, 16);
This.btnClose.Name = "Btnclose";
This.btnClose.TabIndex = 7;
This.btnClose.Text = "Close";
This.btnClose.Click + = new System.EventHandler (This.btnclose_click);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (504, 273);
This. Controls.Add (This.btnclose);
This. Controls.Add (This.btnend);
This. Controls.Add (This.button1);
This. Controls.Add (This.txtmsgsend);
This. Controls.Add (This.txtmessagemain);
This. Controls.Add (This.txtserverip);
This. Controls.Add (This.btnjoin);
This. Controls.Add (This.btnstart);
This. Name = "Form1";
This. Text = "Udpwintest";
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.