/// <summary> /// socket使用UDP协议异步发送消息 /// </summary> /// <param name="data">数据byte[]类型</param> /// <param name="address">远端IP地址</param> public void SendMessage(byte[] data, string address) { IPEndPoint ip = SocketTools.StrToEndPoint(address) as IPEndPoint; string localIPStr = localIP.Address.ToString(); //socket绑定的IP string connectIPStr = ip.Address.ToString(); if (SocketTools.CheckIPGateway(localIPStr, connectIPStr) && connectIPStr != "127.0.0.1" && localIPStr != "127.0.0.1") //同一网段则发送消息 { socket.BeginSendTo(data, 0, data.Length, SocketFlags.None, ip, null, null); } }
/// <summary> /// 发送消息 /// </summary> /// <param name="sentBuffer">发送内容(byte[] 类型)</param> /// <param name="strEndPoint">已连接服务器的远端字符串类型地址</param> public void Send(byte[] sentBuffer, string strEndPoint) { Send(sentBuffer, SocketTools.StrToEndPoint(strEndPoint)); }