public bool Send(int cmd, byte[] data) { int conId = connectId; NetBuffer buf = new NetBuffer(); data = NetEncoder.OnSendData(data); NetEncoder.OnSendHead(buf, cmd, data.Length); buf.WriteBytes(data); try { if (_tcpClient != null && _tcpClient.Connected) { _socketStream.Write(buf.ToBytes(), 0, buf.GetLength()); return(true); } else { return(false); } } catch (Exception e) { Log.Debug("SendCmd error :" + cmd + "," + e.ToString()); Log.Debug("conid:" + conId + "conecntId:" + connectId); if (onReconnect != null && conId == connectId) { onReconnect(); } return(false); } }
public override bool SendCmd(int cmd, byte[] data) { NetBuffer buf = new NetBuffer(); data = NetEncoder.OnSendData(data); NetEncoder.OnSendHead(buf, cmd, data.Length); buf.WriteBytes(data); _socket.Send(buf.ToBytes()); return(true); }