public void UDPSend(ProtocolBase protocol, IPEndPoint remote) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); UDPsocket.SendTo(sendbuff, remote); }
public void SocketSend(ProtocolBase proto, EndPoint endPoint) { byte[] bytes = proto.Encode(); byte[] bytelenght = BitConverter.GetBytes(bytes.Length); byte[] senddata = bytelenght.Concat(bytes).ToArray(); socket.SendTo(senddata, senddata.Length, SocketFlags.None, endPoint); }
public void Send(ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); socket.Send(sendbuff); }
public void Send(ProtocolBase protocolBase) { byte[] bytes = protocolBase.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendBuff = length.Concat(bytes).ToArray(); _socket.Send(sendBuff); Console.WriteLine("send ok!"); }
public bool Send(ProtocolBase protocol) { byte[] b = protocol.Encode(); byte[] length = BitConverter.GetBytes(b.Length); byte[] sendbuff = length.Concat(b).ToArray(); socket.Send(sendbuff); return(true); }
public void UDPSend(ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); IPEndPoint ip = new IPEndPoint(IPAddress.Parse(Host), 9970); UDPsocket.SendTo(sendbuff, ip); }
public void UDPSend(int i, ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); if (conns[i].UDPRemote != null) { UDPsocket.SendTo(sendbuff, conns[i].UDPRemote); } }
public bool Send(ProtocolBase protocol) { if (status != NetworkStatus.Connected) { Debug.Log("[Error] Send Method is error."); return(false); } _socket.Send(protocol.Encode()); Debug.Log("发送消息:" + protocol.Expression); return(true); }
public void Send(Conn conn, ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); try { conn.socket.BeginSend(sendbuff, 0, sendbuff.Length, SocketFlags.None, null, null); } catch (Exception e) { } }
public bool Send(ProtocolBase protocol) { if (status != Status.Connected) { Debug.Log("未连接无法发送"); return(false); } byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); socket.Send(sendbuff); return(true); }
public void Send(Conn conn, ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); try { conn.socket.BeginSend(sendbuff, 0, sendbuff.Length, SocketFlags.None, null, null); }catch (Exception e) { Console.WriteLine("【发送消息】" + conn.GetAdress() + " : " + e.Message); } }
//发送数据 public void Send(ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendBuff = length.Concat(bytes).ToArray(); try { socket.Send(sendBuff); } catch (Exception e) { Debug.Log("客户端数据发送异常:" + e.Message); } }
//发送协议 public bool Send(ProtocolBase protocol) { if (status != Status.Connected) { Debug.LogError("[Connection]还没连接就发送数据"); return(true); } byte[] b = protocol.Encode(); byte[] length = BitConverter.GetBytes(b.Length); byte[] sendBuff = length.Concat(b).ToArray(); socket.Send(sendBuff); Debug.Log("发送消息 " + protocol.GetDesc()); return(true); }
public void Send(ProtocolBase protoco) { byte[] bytes = protoco.Encode(); byte[] lenght = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = lenght.Concat(bytes).ToArray(); try { socket.BeginSend(sendbuff, 0, sendbuff.Length, SocketFlags.None, null, null); } catch (Exception e) { Console.WriteLine("[发送消息] 错误:" + e.Message); } }
private void Send(ProtocolBase protocol) { //string str = textinput.text; byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); try { socket.Send(sendbuff); } catch (Exception e) { Debug.Log("失败" + e.Message); } }
//send 及 重载 public bool Send(ProtocolBase protocolBase) { if (_status != Status.Connected) { Debug.LogError("[Connection]: 没连接就发送数据是不好的 !!!"); return(false); } byte[] b = protocolBase.Encode(); byte[] length = BitConverter.GetBytes(b.Length); byte[] sendbuff = length.Concat(b).ToArray(); _socket.Send(sendbuff); Debug.Log("发送消息 : " + protocolBase.GetDesc()); return(true); }
/// <summary> /// 向客户端发送消息 /// </summary> /// <param name="conn"></param> /// <param name="protocol"></param> public void Send(Conn conn, ProtocolBase protocol) { byte[] bytes = protocol.Encode(); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendBuff = length.Concat(bytes).ToArray(); try { conn.socket.BeginSend(sendBuff, 0, sendBuff.Length, SocketFlags.None, null, null); } catch (System.Exception ex) { Console.WriteLine($"[发送消息]{conn.GetAddress()}:{ex.Message}"); } }
public void Send(ProtocolBase protocol) { //string str = textInput.text; byte[] bytes = protocol.Encode(); //System.Text.Encoding.UTF8.GetBytes (str); byte[] length = BitConverter.GetBytes(bytes.Length); byte[] sendbuff = length.Concat(bytes).ToArray(); socket.Send(sendbuff); //try //{ //socket.Send(bytes); //} //catch //{ //} }
public bool Send(ProtocolBase protoBase) { if (status != Status.Connected) { Console.WriteLine("[Connection.Send] Connection is not exist."); return(false); } byte[] strBytes = protoBase.Encode(); byte[] lenBytes = BitConverter.GetBytes(strBytes.Length); byte[] sendBytes = lenBytes.Concat(strBytes).ToArray(); socket.Send(sendBytes); Console.WriteLine("[Connection.Send] Send protocol: " + protoBase.GetDesc()); return(true); }
/// <summary> /// 发送 /// </summary> /// <param name="cs"></param> /// <param name="msg"></param> public static void Send(ClientState cs, ProtocolBase msg) { //状态判断 if (cs == null) { return; } if (!cs.socket.Connected) { return; } //数据编码 byte[] nameBytes = ProtocolBase.EncodeName(msg); byte[] bodyBytes = ProtocolBase.Encode(msg); int len = nameBytes.Length + bodyBytes.Length; byte[] sendBytes = new byte[2 + len]; //组装数据长度 sendBytes[0] = (byte)(len % 256); sendBytes[1] = (byte)(len / 256); //组装数据名字 Array.Copy(nameBytes, 0, sendBytes, 2, nameBytes.Length); //组装数据消息体 Array.Copy(bodyBytes, 0, sendBytes, 2 + nameBytes.Length, bodyBytes.Length); ByteArray ba = new ByteArray(sendBytes); writeQueue.Enqueue(ba); try { cs.socket.BeginSend(sendBytes, 0, sendBytes.Length, 0, null, null); } catch (SocketException ex) { Console.WriteLine("Socket Close on BeginSend" + ex.ToString()); } }