使用UdpClient怎么总是接收时出问题???

pontus 2004-11-30 11:03:28
代码:
UdpClient UdpA=new UdpClient();
byte[] sendBytes=Encoding.ASCII.GetBytes("hello");
richTextBox1.AppendText("->A "+DateTime.Now+":\r\n"+textBox1.Text+"\r\n");
UdpA.Connect("127.0.0.1",5);
UdpA.Send(sendBytes,sendBytes.Length);
UdpClient UdpB=new UdpClient(5);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5);
while(true)
{
byte[] receiveBytes=UdpB.Receive(ref RemoteIpEndPoint);
string receiveMessage=Encoding.ASCII.GetString(receiveBytes);
richTextBox1.AppendText("<-A "+DateTime.Now+":\r\n"+receiveMessage+"\r\n");
}
UdpA.Close();
UdpB.Close();
...全文
183 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pontus 2004-11-30
  • 打赏
  • 举报
回复
谢谢,知道了,搞定!
pontus 2004-11-30
  • 打赏
  • 举报
回复
不会的也帮我顶顶吧
2002pine 2004-11-30
  • 打赏
  • 举报
回复
你这肯定不行.
当udpA发送时,
udpb还没有实例化,他怎么接收.
pontus 2004-11-30
  • 打赏
  • 举报
回复
up
wangxt 2004-11-30
  • 打赏
  • 举报
回复
帮你顶

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧