Пример #1
0
    public static bool SendUDPStringASCIIHostname(string hostname, int port, string send)
    {
        try
        {
            Socket       socket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            byte[]       data      = Encoding.ASCII.GetBytes(send);
            IPEndPoint[] endPoints = NetworkTools.GetIPEndPointFromHostName(hostname, port);
            for (int i = 0; i < endPoints.Length; i++)
            {
                socket.SendTo(data, endPoints[i]);
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            return(false);
        }

        return(true);
    }