public void SendToMe(ProtoBuf.IExtensible cmd) { if (netLinkSink != null) { netLinkSink.SendToMe(cmd); } }
public void send_proto_msg_to_client(int stype, int ctype, ProtoBuf.IExtensible msg) { Protocol_type = Protocol_Type.protocol_protobuf; byte[] send_bytes = EncodeCmd.Encode_Protobuf(stype, ctype, msg); byte[] tcp_package = TcpPacker.Package(send_bytes); this.client_socket.BeginSend(tcp_package, 0, tcp_package.Length, SocketFlags.None, new AsyncCallback(this.on_send_data), this.client_socket); }
public static bool Send(ProtoBuf.IExtensible msg) { OnSend(msg); var buf = serizlizer.Serialize(msg); return(Proxy.Send(buf)); }
public void SendProtobufCmd(int serviceType, int cmdType, ProtoBuf.IExtensible body = null) { var cmdPackage = CmdPackageProtocol.PackageProtobuf(serviceType, cmdType, body); if (cmdPackage == null) { return; } var tcpPackage = TcpProtocol.Pack(cmdPackage); if (tcpPackage == null) { return; } try { this.clientSocket.BeginSend( tcpPackage, 0, tcpPackage.Length, SocketFlags.None, OnAfterSend, this.clientSocket); } catch (Exception e) { OnConnectError(e); } }
/// <summary> /// 连接到LoginServer,并发送指定的消息 /// </summary> /// <returns></returns> IEnumerator ConnectLoginServer(ProtoBuf.IExtensible cmd) { var remotes = new string[] { "ws://14.17.104.56:7000/shen/user", // 广东佛山 "ws://112.65.197.72:7000/shen/user", // 松江机房 "ws://192.168.85.71:7000/shen/user", // 公司本地 }; foreach (var url in remotes) { foreach (var c in WebSocketClient.Instance.Open(url).AsEnumerable()) { yield return(c); } if (WebSocketClient.Instance.State == WebSocket.State.Open) { WebSocketClient.Instance.Send(cmd); yield break; } Debug.LogWarning("登陆服务器连接错误: " + url); } Debug.LogError("无法连接到登陆服务器"); MessageBox.Show("无法连接到登陆服务器"); }
public void Process(ProtoBuf.IExtensible msg) { //默认处理函数, 相当于switch case 操作 if (msg is clientmsg.s2c_begingame) { } }
/// <summary> /// 重载消息分发器 /// </summary> /// <param name="message"></param> public override void HandleMessage(ProtoBuf.IExtensible message) { if (this.sfs.Debug) { this.log.Info(new string[] { string.Concat(new object[] { "Message: ", message.GetType().FullName, " ", message }) }); } if (!this.requestHandlers.ContainsKey(message.GetType().FullName)) { this.log.Warn(new string[] { "Unknown message name: " + message.GetType().FullName }); } else { RequestProtoBufDelegate requestDelegate = this.requestHandlers[message.GetType().FullName]; requestDelegate(message); } }
//-------------------------------------------------- //Serializer ProtoBufMsg and send 2014-1-14 zxbx public void OnProtoBufDataWrite(ProtoBuf.IExtensible message) { int iHeaderLen = 0; MemoryStream stream = new MemoryStream(); ProtoBufPackageHeader header = new ProtoBufPackageHeader(); iHeaderLen = header.ReturnHeaderLen(); byte[] headbuffer = new byte[iHeaderLen]; stream.Write(headbuffer, 0, iHeaderLen); int messagename_length = this.protoBufserializer.Serialize(message, stream); header.MessageLength = (int)stream.Length; //effective data len header.MessageType = (byte)6; header.MessageTypeLength = messagename_length; //ByteArray byteArray = new ByteArray(stream.GetBuffer()); byte[] byteT = new byte[header.MessageLength]; ByteArray byteArray = new ByteArray(byteT); ByteArray byteTcp = new ByteArray(stream.GetBuffer()); Buffer.BlockCopy(byteTcp.Bytes, 0, byteArray.Bytes, 0, header.MessageLength); //UnityEngine.Debug.Log("Message Buffer with empty header-->" + DefaultObjectDumpFormatter.HexDump(byteArray)); this.bitSwarm.ThreadManager.EnqueueSend(new WriteProtoBufBinaryDataDelegate(this.WriteProtoBufBinaryData), header, byteArray); }
public void UdpSendProtobufCmd(int serviceType, int cmdType, ProtoBuf.IExtensible body = null) { var cmdPackage = CmdPackageProtocol.PackageProtobuf(serviceType, cmdType, body); if (cmdPackage == null) { return; } try { this.udpSocket.BeginSendTo( cmdPackage, 0, cmdPackage.Length, SocketFlags.None, this.udpRemotePoint, OnUdpSend, this.udpSocket); } catch (Exception e) { OnError(e); } }
public static WWW SetUpRecvResult(ProtoBuf.IExtensible serializableRequest, string url, bool isGet) { byte[] bytes; Dictionary <string, string> mods = new Dictionary <string, string>(); mods.Add("X-Auth-Token", SenseixSession.GetAuthToken()); mods.Add("X-Access-Token", SenseixSession.GetAccessToken()); mods.Add("Content-Type", "application/protobuf"); MemoryStream requestMessageStream = new MemoryStream(); ThinksyProtosSerializer serializer = new ThinksyProtosSerializer(); //UnityEngine.Debug.Log ("Serializing request"); serializer.Serialize(requestMessageStream, serializableRequest); bytes = requestMessageStream.ToArray(); requestMessageStream.Close(); WWW recvResult; if (!isGet) { //UnityEngine.Debug.Log("POST"); recvResult = new WWW(url, bytes, mods); } else { //UnityEngine.Debug.Log("GET"); recvResult = new WWW(url, null, mods); } return(recvResult); }
public void Send(ProtoBuf.IExtensible cmd) { if (netLink == null) { return; } try { var package = VarlenProtobufCommandSerializer.Instance().Serialize(cmd); var ok = packageSerializer.Write(package, netLink, bFirstMsg); if (ok) { bFirstMsg = false; if ((cmd is Pmd.ForwardBwNullUserPmd_CS) == false && LogFilter(cmd)) { if (Engine.Utility.Log.MaxLogLevel >= Engine.Utility.LogLevel.LogLevel_Group) { Engine.Utility.Log.LogGroup(GameDefine.LogGroup.Net, "<color=green>[SEND]</color>{0}: {1}\n{2}", VarlenProtobufCommandSerializer.Instance()[cmd.GetType()], cmd.GetType().Name, cmd.Dump()); } } } else { if (Engine.Utility.Log.MaxLogLevel >= Engine.Utility.LogLevel.LogLevel_Group) { Engine.Utility.Log.LogGroup(GameDefine.LogGroup.Net, "<color=red>[SEND ERROR]</color>{0}: {1}\n{2}", VarlenProtobufCommandSerializer.Instance()[cmd.GetType()], cmd.GetType().Name, cmd.Dump()); } } } catch (Exception ex) { packageSerializer.OnError(ex); } }
public bool SendMessage(int type, ProtoBuf.IExtensible msg) { if (!_isConnected) { return(false); } System.IO.MemoryStream stream = new System.IO.MemoryStream(); ProtoBuf.Serializer.Serialize(stream, msg); byte[] bMsg = stream.ToArray(); int len = 4 + 4 + bMsg.Length; int rLen = IPAddress.HostToNetworkOrder(len); byte[] bLen = BitConverter.GetBytes(rLen); int rIndex = IPAddress.HostToNetworkOrder(_index); byte[] bIndex = BitConverter.GetBytes(rIndex); int rType = IPAddress.HostToNetworkOrder(type); byte[] bType = BitConverter.GetBytes(rType); byte[] bSend = new byte[4 + len]; Array.Copy(bLen, 0, bSend, 0, 4); Array.Copy(bIndex, 0, bSend, 4, 4); Array.Copy(bType, 0, bSend, 8, 4); Array.Copy(bMsg, 0, bSend, 12, len - 8); _socketClient.Send(bSend); ++_index; return(true); }
public byte[] Serialize(ProtoBuf.IExtensible message) { using (var mem = new MemoryStream()) { SerializeTo(mem, message); return(mem.ToArray()); } }
public static IEnumerator CoroutinePostRequest(ProtoBuf.IExtensible serializableRequest, ResponseHandlerDelegate responseHandler, string url, bool isGet) { //UnityEngine.Debug.Log ("set up recv result"); WWW recvResult = SetUpRecvResult(serializableRequest, url, isGet); yield return(GetSingletonInstance().StartCoroutine( CoroutinePostRequest(recvResult, serializableRequest, responseHandler, url))); }
public void udp_send_protobuf_cmd(int stype, int ctype, ProtoBuf.IExtensible body) { byte[] cmd_data = proto_man.pack_protobuf_cmd(stype, ctype, body); if (cmd_data == null) { return; } this.udp_socket.BeginSendTo(cmd_data, 0, cmd_data.Length, SocketFlags.None, this.udp_remote_point, new AsyncCallback(this.on_udp_send_data), this.udp_socket); }
private void OnS2C_IntoLevels(ProtoBuf.IExtensible msg) { clientmsg.s2c_intolevels intolevels = msg as clientmsg.s2c_intolevels; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = intolevels; AWEvent evt = new AWEvent(AWEvent.S2C_INTOLEVELS, hashtable); this.sfs.DispatchEvent(evt); }
public void send_protobuf_cmd(int stype, int ctype, ProtoBuf.IExtensible body) { byte[] cmd_data = proto_man.pack_protobuf_cmd(stype, ctype, body); if (cmd_data == null) { Debug.Log("cmd_data is null"); } byte[] tcp_pkg = tcp_packer.pack(cmd_data); this.client_socket.BeginSend(tcp_pkg, 0, tcp_pkg.Length, SocketFlags.None, new AsyncCallback(this.on_send_data_cb), this.client_socket); }
public void SendProtocol(int protocolId, ProtoBuf.IExtensible iProtocol) { ProtocolItem tProtocolItem = new ProtocolItem(protocolId, iProtocol); lock (_sendQueue) { _sendQueue.Enqueue(tProtocolItem); } _waitSend.Set();//启动被ManualResetEvent阻塞的线程 }
private void DispatchRequest(ProtoBuf.IExtensible message) { IController controller = this.bitSwarm.GetController(2); if (controller == null) { throw new AWError("Cannot handle server response. Unknown controller, id: " + 2); } controller.HandleMessage(message); }
public bool TryApplyMessage(ProtoBuf.IExtensible message, DemoParser parser) { if (message is Messages.CSVCMsg_CreateStringTable) { parser.StringTablesParser.stringTables.Add((Messages.CSVCMsg_CreateStringTable)message); return(true); } return(false); }
private void OnS2C_MyHero(ProtoBuf.IExtensible msg) { clientmsg.s2c_myhero myhero = msg as clientmsg.s2c_myhero; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = myhero; AWEvent evt = new AWEvent(AWEvent.S2C_MYHERO, hashtable); this.sfs.DispatchEvent(evt); }
private void OnS2C_FightBegin(ProtoBuf.IExtensible msg) { clientmsg.s2c_fightbegin fightbegin = msg as clientmsg.s2c_fightbegin; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = fightbegin; AWEvent evt = new AWEvent(AWEvent.S2C_FIGHTBEGIN, hashtable); this.sfs.DispatchEvent(evt); }
public void SendToMe(ProtoBuf.IExtensible message) { IEnumerator coroutine; Dispatcher.Dispatch(message, out coroutine); if (coroutine != null) { StartCoroutine(coroutine); } }
private void OnS2C_IntoemBattle(ProtoBuf.IExtensible msg) { clientmsg.s2c_intoembattle intoembattle = msg as clientmsg.s2c_intoembattle; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = intoembattle; AWEvent evt = new AWEvent(AWEvent.S2C_INTOEMBATTLE, hashtable); this.sfs.DispatchEvent(evt); }
private void OnS2C_IntoDungeon(ProtoBuf.IExtensible msg) { clientmsg.s2c_intodungeon intodungeon = msg as clientmsg.s2c_intodungeon; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = intodungeon; AWEvent evt = new AWEvent(AWEvent.S2C_INTODUNGEON, hashtable); this.sfs.DispatchEvent(evt); }
private void OnS2C_IntoMainWorld(ProtoBuf.IExtensible msg) { clientmsg.s2c_intomainworld intomainworld = msg as clientmsg.s2c_intomainworld; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = intomainworld; AWEvent evt = new AWEvent(AWEvent.S2C_INTOMAINWORLD, hashtable); this.sfs.DispatchEvent(evt); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="message"></param> public static void SendMessage(IOSession session, int msgid, ProtoBuf.IExtensible message) { if (session != null) { session.WriteAndFlush(msgid, MessageSerialize(message)); } else { log.Error("session:为空 发送消息 " + message.GetType().FullName); } }
private void OnS2C_CreateChar(ProtoBuf.IExtensible msg) { UnityEngine.Debug.Log("SystemProtoBufController--------->OnS2C_CreateChar"); clientmsg.s2c_createchar createchar = msg as clientmsg.s2c_createchar; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = createchar; AWEvent evt = new AWEvent(AWEvent.S2C_CREATECHAR, hashtable); this.sfs.DispatchEvent(evt); }
private void OnS2C_BeginGame(ProtoBuf.IExtensible msg) { UnityEngine.Debug.Log("SystemProtoBufController-------->OnS2C_ResponseLoginGame"); clientmsg.s2c_begingame logingame = msg as clientmsg.s2c_begingame; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = logingame; AWEvent evt = new AWEvent(AWEvent.S2C_BEGINGAME, hashtable); this.sfs.DispatchEvent(evt); }
private void OnS2C_ResponseProofTime(ProtoBuf.IExtensible msg) { UnityEngine.Debug.Log("SystemProtoBufController------>OnS2C_ResponseProofTime"); clientmsg.S2CProofTime prooftime = msg as clientmsg.S2CProofTime; Hashtable hashtable = new Hashtable(); hashtable["protomsg"] = prooftime; AWEvent evt = new AWEvent(AWEvent.RESPONSE_PROOFTIME, hashtable); this.sfs.DispatchEvent(evt); }
public void send(global::ProtoBuf.IExtensible base_msg) { mCachedMsg = base_msg; String name = base_msg.ToString(); byte[] byteArray = System.Text.Encoding.Default.GetBytes(name); UInt32 name_length = (UInt32)byteArray.Length; System.IO.MemoryStream mem = new System.IO.MemoryStream(); ProtoBuf.Serializer.Serialize<global::ProtoBuf.IExtensible>(mem, base_msg); UInt32 length = (UInt32)mem.Length; byte[] bytes = new byte[length]; Array.Copy(mem.GetBuffer(), bytes, length); UInt32 pb_flag = 0; UInt16 mask = 0; mask = 1 << 2; UInt32 crc32 = 0; //crc32 = (UInt32)CRC32.GetCRC32(bytes); UInt32 source_base64_length = sizeof(UInt32) + sizeof(UInt32) + name_length + length; UInt32 head_length = sizeof(UInt16) + sizeof(UInt32); UInt32 max_length = 0;//= sizeof(UInt16) + sizeof(UInt32) + source_base64_length; UInt32 body_length = 0; byte[] base64_buff = new byte[source_base64_length]; ////////// UInt32 write_pos = 0; UInt32 write_length = sizeof(UInt32); Array.Copy(BitConverter.GetBytes(pb_flag), 0, base64_buff, write_pos, write_length); write_pos += write_length; write_length = sizeof(UInt32); Array.Copy(BitConverter.GetBytes(name_length), 0, base64_buff, write_pos, write_length); write_pos += write_length; write_length = name_length; Array.Copy(System.Text.Encoding.UTF8.GetBytes(name), 0, base64_buff, write_pos, write_length); write_pos += write_length; write_length = length; Array.Copy(bytes, 0, base64_buff, write_pos, write_length); write_pos += write_length; UInt32 char_base64_out_length = write_pos * 2; char[] base64_out = new char[char_base64_out_length]; int base64_length = Convert.ToBase64CharArray(base64_buff, 0, (int)write_pos, base64_out, 0); string base64_str = new string(base64_out, 0, base64_length); //Debug.Log("base64[" + base64_str + "]"); byte[] body_bytes = System.Text.Encoding.UTF8.GetBytes(base64_out, 0, base64_length); body_length = (UInt32)body_bytes.Length; max_length = head_length + body_length; byte[] sendbuff = new byte[max_length]; //// write_length = sizeof(UInt16); write_pos = 0; Array.Copy(BitConverter.GetBytes(mask), sendbuff, write_length); write_pos += write_length; write_length = sizeof(UInt32); crc32 = (UInt32)CRC32.GetCRC32(body_bytes); Array.Copy(BitConverter.GetBytes(crc32), 0, sendbuff, write_pos, write_length); write_pos += write_length; write_length = body_length; Array.Copy(body_bytes, 0, sendbuff, write_pos, write_length); socket_client.Send(sendbuff); }