static private void ProcessMsgFromThread(RSProtoBuffSSHMsg msg) { System.Console.WriteLine("got msg"); /* * So we received a RPC message. What do we know at this point? * We know that the magic code of the message is ok which means that the chance is high that the rest is ok, too. * * * First of all we should check if the message is a response. * Since the server only sends responses we do not expect anything else. * * Note: actually the lib is doing this on its own and you can skip this test. * (I keep it for educational purpose :P) */ if (!RSProtoBuf.IsRpcMsgIdResponse(msg.MsgID)) { return; } /* * Next step is to get the informations about the message: * extension, service and submsg * * These 3 things define the content of the message. * (In this example i only requested the system status so i only expect a response to this call) */ byte extension = RSProtoBuf.GetRpcMsgIdExtension(msg.MsgID); ushort service = RSProtoBuf.GetRpcMsgIdService(msg.MsgID); byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID); // check extension if (extension != (byte)rsctrl.core.ExtensionId.CORE) { return; } // check service if (service != (ushort)rsctrl.core.PackageId.SYSTEM) { return; } // check submsg if (submsg != (byte)rsctrl.system.ResponseMsgIds.MsgId_ResponseSystemStatus) { return; } /* * Now we know the content of the message and can deserialize it * (The example message is a response to our system status request!) */ rsctrl.system.ResponseSystemStatus response = new rsctrl.system.ResponseSystemStatus(); Exception e; if (!RSProtoBuf.Deserialize <rsctrl.system.ResponseSystemStatus>(msg.ProtoBuffMsg, out response, out e)) { System.Console.WriteLine("ProcessSystemstatus: error deserializing " + e.Message); } /* * Last thing you should do is to check if the response.status is SUCCESS. * In any other case something went wrong. * * After this you can continue processing the message in the proper way e.g. update system status */ if (response.status == null || response.status.code != rsctrl.core.Status.StatusCode.SUCCESS) { return; } System.Console.WriteLine("Systemstatus: "); System.Console.WriteLine(" -- peers: " + response.no_peers); System.Console.WriteLine(" -- online: " + response.no_connected); }
private static void ProcessMsgFromThread(RSProtoBuffSSHMsg msg) { System.Console.WriteLine("got msg"); /* * So we received a RPC message. What do we know at this point? * We know that the magic code of the message is ok which means that the chance is high that the rest is ok, too. * * * First of all we should check if the message is a response. * Since the server only sends responses we do not expect anything else. * * Note: actually the lib is doing this on its own and you can skip this test. * (I keep it for educational purpose :P) */ if (!RSProtoBuf.IsRpcMsgIdResponse(msg.MsgID)) return; /* * Next step is to get the informations about the message: * extension, service and submsg * * These 3 things define the content of the message. * (In this example i only requested the system status so i only expect a response to this call) */ byte extension = RSProtoBuf.GetRpcMsgIdExtension(msg.MsgID); ushort service = RSProtoBuf.GetRpcMsgIdService(msg.MsgID); byte submsg = RSProtoBuf.GetRpcMsgIdSubMsg(msg.MsgID); // check extension if(extension != (byte) rsctrl.core.ExtensionId.CORE) return; // check service if (service != (ushort)rsctrl.core.PackageId.SYSTEM) return; // check submsg if (submsg != (byte)rsctrl.system.ResponseMsgIds.MsgId_ResponseSystemStatus) return; /* * Now we know the content of the message and can deserialize it * (The example message is a response to our system status request!) */ rsctrl.system.ResponseSystemStatus response = new rsctrl.system.ResponseSystemStatus(); Exception e; if (!RSProtoBuf.Deserialize<rsctrl.system.ResponseSystemStatus>(msg.ProtoBuffMsg, out response, out e)) System.Console.WriteLine("ProcessSystemstatus: error deserializing " + e.Message); /* * Last thing you should do is to check if the response.status is SUCCESS. * In any other case something went wrong. * * After this you can continue processing the message in the proper way e.g. update system status */ if (response.status == null || response.status.code != rsctrl.core.Status.StatusCode.SUCCESS) return; System.Console.WriteLine("Systemstatus: "); System.Console.WriteLine(" -- peers: " + response.no_peers); System.Console.WriteLine(" -- online: " + response.no_connected); }