protected override bool sendDetail(RpcMessage m) { if (_sock == null) { if (!connect()) { return(false); } } if (_sent_num == 0) //第一次连接进入之后的第一个数据包需要携带令牌和设备标识码,用于接入服务器的验证 { if (_token != null && !_token.Equals("")) { m.extra.setPropertyValue("__token__", _token); m.extra.setPropertyValue("__device_id__", RpcCommunicator.getSystemDeviceID()); } } byte[] body = null; body = ((MemoryStream)m.marshall()).ToArray(); byte[] hdr = createMetaPacketHeader(body.Length); _sock.Send(hdr); _sock.Send(body); _sent_num++; return(true); }
protected MemoryStream createMsgBody(RpcMessage m) { //byte[] hdrbBytes = null; MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); MemoryStream bodystream = (MemoryStream)m.marshall(); byte[] bytes = bodystream.ToArray(); unchecked { writer.Write((uint)IPAddress.HostToNetworkOrder((int)PACKET_META_MAGIC)); } writer.Write((uint)IPAddress.HostToNetworkOrder(bytes.Length + META_PACKET_HDR_SIZE - 4)); writer.Write((byte)RpcConstValue.COMPRESS_NONE); writer.Write((byte)RpcConstValue.ENCRYPT_NONE); writer.Write((uint)IPAddress.HostToNetworkOrder(VERSION)); writer.Write(bytes); //hdrbBytes = stream.ToArray(); //return hdrbBytes; return(stream); }
protected MemoryStream createMsgBody(RpcMessage m) { //byte[] hdrbBytes = null; MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); MemoryStream bodystream = (MemoryStream) m.marshall(); byte[] bytes = bodystream.ToArray(); unchecked { writer.Write((uint)IPAddress.HostToNetworkOrder((int)PACKET_META_MAGIC)); } writer.Write((uint)IPAddress.HostToNetworkOrder(bytes.Length + META_PACKET_HDR_SIZE - 4)); writer.Write((byte)RpcConstValue.COMPRESS_NONE); writer.Write((byte)RpcConstValue.ENCRYPT_NONE); writer.Write((uint)IPAddress.HostToNetworkOrder(VERSION)); writer.Write(bytes); //hdrbBytes = stream.ToArray(); //return hdrbBytes; return stream; }