上海大学 计算机网络 实验报告 联系客服

发布时间 : 星期日 文章上海大学 计算机网络 实验报告更新完毕开始阅读e5093a47cd22bcd126fff705cc17552706225efa

页眉 using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;

using System.Windows.Forms; using System.Net;

using System.Net.Sockets; using System.Threading; namespace UDP接收端 {

public partial class UdpReceiveForm : Form {

private bool ReadFlag = true; private Thread th;

private IPEndPoint remote; private UdpClient server; private int count = 0; private double num; public UdpReceiveForm() {

InitializeComponent(); }

private void read() { try {

server = new UdpClient(8010);//创建端口为8010的socket } catch

21 / 22

页眉 {

MessageBox.Show(\创建端口失败!\, \错误\); return; }

Encoding enc = Encoding.Unicode; remote = null; while (true) {

Byte[] data = server.Receive(ref remote); String strData = enc.GetString(data);

this.lbReceiveMessage.Items.Insert(0, strData); } // while }

private void btnReceive_Click(object sender, EventArgs e) {

//创建一个线程

th = new Thread(new ThreadStart(read));//执行read函数 //启动线程 th.Start();

this.lblInfo.Text = \程序处于数据接收状态!\; }

private void UdpReceiveForm_FormClosing(object sender, FormClosingEventArgs e) {

if (th != null && th.ThreadState != ThreadState.Stopped) th.Abort(); } } }

22 / 22