UdpClient 实例化时无参数和用端口参数:2112 ,它们之间有什么区别啊? UdpClient Uclient=new UdpClient(2112);UdpClient Uclient=new UdpClient();这两种有什么区别啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我写的Win程序时,必须用绑定端口的实例,这是什么原因啊?Win的代码: private IPEndPoint hostPoint; private IPEndPoint remotePoint=new IPEndPoint(IPAddress.Any, 0); private UdpClient client=new UdpClient(2112); private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtPort; private Thread listenThread;...private void btnSend_Click(object sender, System.EventArgs e) { hostPoint = new IPEndPoint(IPAddress.Parse(txtserverIP.Text), int.Parse(txtPort.Text)); Encoding encod=Encoding.UTF8; byte[] Message=encod.GetBytes(richTxtSend.Text); client.Send(Message,Message.Length, hostPoint); } public void UDPListen() { byte[] buffer; while (true) { buffer = client.Receive(ref remotePoint); Encoding encod=Encoding.UTF8; string returnData = encod.GetString(buffer); richTxtHistory.Text=richTxtHistory.Text+"信息来自IP:"+remotePoint.Address.ToString()+" 端口:"+remotePoint.Port+"\r\n"+returnData+"\r\n"+"\r\n"; } } 在建立了套接字之后,必须把它绑定到系统中一个指定的网络地址和端口,或绑定到一个远程网络地址端口,一旦套接字被绑定,就可以用它在网络上发送和接收数据。UdpClient Uclient=new UdpClient(2112); 是直接绑定, client.Send(Message,Message.Length, hostPoint);这样是绑定到hostPoint上面,都要绑定的 UdpClient Uclient=new UdpClient(); ====此构造函数创建一个新的 UdpClient,并允许基础服务提供程序分配最合适的本地 IPv4 地址和端口号。自动分配端口号 C#实现压缩文件的问题? 怎样提取特定内容 鼠标右键点击LISTVIEW中的一行,那一行就被选中而且高亮。怎么实现? vs05 Listview双击或者单击弹出新窗体怎么做啊? 简单!请修正....... C#基本問題 ComboBox下拉列表的问题,在线急等!!!谢谢 在DataGrid1中用radiobuttonlist C# 利用delegate绘图、重绘表格,速度超慢 大家帮我看看这段话,我总是看不懂,谢谢. 多线程操作数据表 急急!!!如何在子窗体上加richtextbox
Win的代码:
private IPEndPoint hostPoint;
private IPEndPoint remotePoint=new IPEndPoint(IPAddress.Any, 0);
private UdpClient client=new UdpClient(2112);
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtPort;
private Thread listenThread;
...
private void btnSend_Click(object sender, System.EventArgs e)
{
hostPoint = new IPEndPoint(IPAddress.Parse(txtserverIP.Text), int.Parse(txtPort.Text));
Encoding encod=Encoding.UTF8;
byte[] Message=encod.GetBytes(richTxtSend.Text);
client.Send(Message,Message.Length, hostPoint);
} public void UDPListen()
{
byte[] buffer;
while (true)
{
buffer = client.Receive(ref remotePoint);
Encoding encod=Encoding.UTF8;
string returnData = encod.GetString(buffer);
richTxtHistory.Text=richTxtHistory.Text+"信息来自IP:"+remotePoint.Address.ToString()+" 端口:"+remotePoint.Port+"\r\n"+returnData+"\r\n"+"\r\n";
}
}
是直接绑定, client.Send(Message,Message.Length, hostPoint);
这样是绑定到hostPoint上面,都要绑定的
====
此构造函数创建一个新的 UdpClient,并允许基础服务提供程序分配最合适的本地 IPv4 地址和端口号。
自动分配端口号