public virtual void serialize() { sendBuffer.resetPosition(); sendBuffer.position = 4; sendBuffer.writeByte(Cmd); sendBuffer.writeByte(Para); //sendBuffer.writeUint(dwTime); }
//发送协议 public bool sendCmd(BaseCmd _cmd) { if (!m_isConnected) { Debug.LogErrorFormat("当前未连接服务器! {0}", DateTime.Now); } if (_cmd.getSize() <= 0 || !m_isConnected || m_sendLock) { Debug.LogWarning("send field"); return(false); } // Debug.Log("[SEND] cmd : " + _cmd.Cmd.ToString() + " para :" + _cmd.Para.ToString() + " msgLength : " + _cmd.getSize().ToString()); int _message_length = _cmd.getSize(); //BytesBuffer _sendBuf = new BytesBuffer (_message_length); BytesBuffer _sendBuf = _cmd.sendBuffer; _sendBuf.resetPosition(); _sendBuf.writeInt32(_message_length - 4); //System.Buffer.BlockCopy (_cmd.getBuffer.bytes, 0, _sendBuf.bytes, 4, _cmd.getSize()); if (_sendAsyncCallback == null) { _sendAsyncCallback = new AsyncCallback(_onSendMsg); } //m_ClientSocket.Client.BeginSend (_sendBuf.bytes, 0, _sendBuf.bytes.Length, SocketFlags.None, _sendAsyncCallback, m_ClientSocket); m_ClientSocket.Client.Send(_sendBuf.bytes, 0, _message_length, SocketFlags.None); /* 断包测试 * int bl = 5; * m_ClientSocket.Client.Send (_sendBuf.bytes, 0, _sendBuf.bytes.Length - bl, SocketFlags.None); * System.Threading.Thread.Sleep (1000); * m_ClientSocket.Client.Send (_sendBuf.bytes, bl, bl, SocketFlags.None); * ///*/ return(true); }