public bool Send(ProtocolBase protocol) { if (status != Status.Connected) { Console.WriteLine("尚未连接,发送失败"); return(false); } byte[] sendBuff = NetPackage.EncoderHeader(protocol); socket.Send(sendBuff); //Debug.Log("发送消息 " + protocol.GetDesc()); return(true); }
public void Send(Conn conn, ProtocolBase protocol) { int start = 0; string protoName = protocol.GetString(start, ref start); Console.WriteLine("发送消息:" + protoName + " 到:" + conn.GetAddress()); byte[] sendBuff = NetPackage.EncoderHeader(protocol); try { conn.socket.BeginSend(sendBuff, 0, sendBuff.Length, SocketFlags.None, null, null); } catch (Exception e) { Console.WriteLine("[发送消息]" + conn.GetAddress() + " : " + e.Message); } }