1. 连接方式1

    UdpClient udpClient = new UdpClient(11000);

    udpClient.Connect("192.168.0.5", 11000);

    Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");

    udpClient.Send(sendBytes, sendBytes.Length);

     

    以上是一种连接方式,Connect和Send配合。

  2. 连接方式2

    UdpClient udpClientB = new UdpClient(11001);

    udpClientB.Send(sendBytes, sendBytes.Length, "192.168.0.5", 11000);

     

    直接用Send函数的这个重载就不用单独Connect()了。

  3. 关于构造函数

空的构造函数是不行的,比如想建立一个本地端点:

UdpClient udpClientC = new UdpClient();

这样不行,这样Client属性的LocalEndPoint=null。

相关文章:

  • 2021-05-15
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-01-19
猜你喜欢
  • 2021-10-24
  • 2021-06-24
  • 2021-11-18
  • 2021-08-30
  • 2021-08-19
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案