本文整理汇总了C#中NetMQMessage.ReadJson方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQMessage.ReadJson方法的具体用法?C# NetMQMessage.ReadJson怎么用?C# NetMQMessage.ReadJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQMessage
的用法示例。
在下文中一共展示了NetMQMessage.ReadJson方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleFrameMessage
public void HandleFrameMessage(ResponseSocket server, NetMQMessage msg)
{
Debug.Log ("Handling Message");
if (logTimingInfo || logSimpleTimeInfo)
{
DateTime newTime = DateTime.Now;
Debug.LogFormat("Time since received last msg: {0} ms", newTime.Subtract(_timeForLastMsg).TotalMilliseconds);
_timeForLastMsg = newTime;
}
if (debugNetworkMessages)
Debug.LogFormat("Received Msg on Server: {0}", ReadOutMessage(msg));
string msgHeader = msg.First.ConvertToString();
JsonData jsonData = msg.ReadJson(out msgHeader);
if (jsonData == null)
{
Debug.LogError("Invalid message from client! Cannot parse JSON!\n" + ReadOutMessage(msg));
return;
}
if (msgHeader == null)
{
Debug.LogError("Invalid message from client! No msg_type!\n" + jsonData.ToJSON());
return;
}
switch(msgHeader.ToString())
{
case MSG_R_Terminate:
Application.Quit ();
break;
case MSG_R_ClientJoin:
OnClientJoin(server, jsonData);
RecieveClientInput(server, jsonData);
break;
case MSG_R_FrameInput:
RecieveClientInput(server, jsonData);
break;
case MSG_R_ClientJoinWithConfig:
Debug.Log ("Config received!");
ReceiveSceneSwitch (server, jsonData);
Debug.Log ("Config handled!");
break;
case MSG_R_SceneSwitch:
ReceiveSceneSwitch(server, jsonData);
break;
default:
Debug.LogWarningFormat("Invalid message from client! Unknown msg_type '{0}'\n{1}", msgHeader, jsonData.ToJSON());
break;
}
}
示例2: HandleClientFrameMessage
// Used for debugging without an agent
public void HandleClientFrameMessage(RequestSocket client, NetMQMessage msg)
{
if (debugNetworkMessages)
Debug.LogFormat("Received Msg on Client: {0}", ReadOutMessage(msg));
string msgHeader = msg.First.ConvertToString();
// Hack to avoid slow parsing of long json values since we're not reading it anyways
JsonData jsonData = null;
if (msg.FrameCount > 0)
{
string jsonString = msg[0].ConvertToString();
if (jsonString != null && jsonString.Length > 1000)
{
msgHeader = MSG_S_FrameData;
jsonData = CreateMsgJson(msgHeader);
}
else
jsonData = msg.ReadJson(out msgHeader);
}
if (jsonData == null)
{
Debug.LogError("Invalid message from server! Cannot parse JSON!\n" + ReadOutMessage(msg));
return;
}
if (msgHeader == null)
{
Debug.LogError("Invalid message from server! No msg_type!\n" + jsonData.ToJSON());
return;
}
switch(msgHeader.ToString())
{
case MSG_S_ConfirmClientJoin:
SimulateClientInput(client, jsonData, msg);
break;
case MSG_S_FrameData:
SimulateClientInput(client, jsonData, msg);
break;
default:
Debug.LogWarningFormat("Invalid message from server! Unknown msg_type '{0}'\n{1}", msgHeader, jsonData.ToJSON());
break;
}
}