• UDP发送和接收


    发送函数

    public bool udpSend(string ip, int port, byte[] data)
    {
        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        IPAddress ipaddress = IPAddress.Parse(ip);
        IPEndPoint ipendpoint = new IPEndPoint(ipaddress, port);
        socket.SendTo(data, ipendpoint);
        socket.Close();
        return true;
    }

    接收

    int port = 8001;
    UdpClient udp_client = new UdpClient(port);
    IPEndPoint ip_endpoint = new IPEndPoint(IPAddress.Any, port);
    while (true)
    {
        byte[] data = udp_client.Receive(ref ip_endpoint);
    }
  • 相关阅读:
    【游戏开发】Excel表格批量转换成CSV的小工具
    iOS
    iOS
    Xcode
    iOS
    iOS
    iOS
    iOS
    iOS
    iOS
  • 原文地址:https://www.cnblogs.com/xieqianli/p/5126163.html
Copyright © 2020-2023  润新知