欢迎来到天天文库
浏览记录
ID:51489625
大小:376.06 KB
页数:6页
时间:2020-03-25
《网络编程实验.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、网络编程实验实验一IPAddress类、Dns类、IPHostEntry类和IPEndPoint类的使用方法。1.界面(各控件名称如图所示)textBox1listBox1Button1Button22、代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Fo
2、rms;usingSystem.Net;namespaceWindowsFormsApplication4{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){listBox1.Items.Clear();stringname=Dns.GetHostName();listBox1.Items.Add("本机主机名:"+name);IPHostEntryme=D
3、ns.GetHostEntry(name);listBox1.Items.Add("本机所有的IP地址:");foreach(IPAddressipinme.AddressList){listBox1.Items.Add(ip);}IPAddresslocalip=IPAddress.Parse("127.0.0.1");IPEndPointiep=newIPEndPoint(localip,80);listBox1.Items.Add("theIPEndPointis:"+iep.ToString());listBox1.Items.
4、Add("theAddressis:"+iep.Address);listBox1.Items.Add("theAddressFamilyis:"+iep.AddressFamily);listBox1.Items.Add("themaxportnumberis:"+IPEndPoint.MaxPort);listBox1.Items.Add("theminportnumberis:"+IPEndPoint.MinPort);}privatevoidbutton2_Click(objectsender,EventArgse){listB
5、ox1.Items.Clear();IPHostEntryremoteHost=Dns.GetHostEntry(textBox1.Text);IPAddress[]remoteIp=remoteHost.AddressList;listBox1.Items.Add(remoteHost.HostName);listBox1.Items.AddRange(remoteIp);}}}实验二UDP进程通信,编写简易聊天工具。1、界面各控件名称如图所示。txtLocalPortbtnStarttxtLocalIPtxtSendPorttxtS
6、endIPbtnSendMsgchkAnonylstReceiveMsgtxtSendMsg2、代码如下usingSystem;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;usingSystem.Data;usingSystem.Drawing;usingSystem.Windows.Forms;usingSystem.Threading;usingSystem.Collections.Generic;usingSystem.ComponentModel;namesp
7、ace_006_UPD进程通信_Template{publicpartialclassfrmMain:Form{//显示消息回调privatedelegatevoidShowMsgCallBack(stringtext);privateShowMsgCallBackshowMsgCallBack;privateUdpClientmyUdpClient;//UDP客户端privateUdpClientanonyUdpClient;//匿名UDP客户端//窗构造方法publicfrmMain(){InitializeComponent();
8、}//窗体启动加载事件privatevoidfrmMain_Load(objectsender,EventArgse){//初始化回调showMsgCallBack=newShowMsgCallBack(S
此文档下载收益归作者所有