tesses-rpc/HOWTOOTHERLANG.txt

138 lines
2.5 KiB
Plaintext

{
"Id": <number>,
"Value": <json token>,
"Type": "<your enum value>",
"MessageState": 0=Forget, 1=RequestNoForget, 2=ResponseNoForget
}
namespace CSharpExample
{
public interface IMessage
{
}
public class MessageA : IMessage
{
public int Number {get;set;}
}
public class MessageB : IMessage
{
public string Text {get;set;}
}
public enum MessageType
{
Integer=0,
Text=1
}
... Start registering (server) ...
messager.Register<MessageA>(MessageType.Integer,(e)=>{
e.Data.Number *= 7;
if(e.NeedReply)
{
m.Reply(e.Data);
}
});
messager.Register<MessageB>(MessageType.Text,null);
... End registering (server) ...
... Start registering (client) ...
messager.Register<MessageA>(MessageType.Integer,(e)=>{
e.Data.Number = 55;
if(e.NeedReply)
{
m.Reply(e.Data);
}
});
messager.Register<MessageB>(MessageType.Text,(e)=>{
e.Data.Text += " C#";
if(e.NeedReply)
{
m.Reply(e.Data);
}
});
... End registering (client) ...
... Start initial sending (server) ...
messager.SendMessage(new MessageB(){Text="Hello, World"},(msg)=>{
//do something with value
});
messager.SendMessage(new MessageA(){Number=8},(msg)=>{
//do something with value
});
... End initial sending (server) ...
... Start initial sending (client) ...
messager.SendMessage(new MessageA(){Number=6},(msg)=>{
//do something with value
});
messager.SendMessage(new MessageA(){Number=33});
... End initial sending (client) ...
}
json (client => server) (in an ideal world where messages are sent/received in order, server goes first and json is indented)
{
"Id": 0,
"Value": {
"Text": "Hello, World C#"
},
"Type": "Text",
"MessageState": 2
}
{
"Id":1,
"Value":{
"Number": 55
},
"Type":"Integer",
"MessageState": 2
}
//this one is zero because this is the first message originated by client
{
"Id": 0,
"Value": {
"Number":6
},
"Type":"Integer",
"MessageState": 1
}
{
"Id": 1,
"Value": {
"Number": 33,
},
"Type": "Integer",
"MessageType": 0
}
json (server => client) (in an ideal world where messages are sent/received in order, server goes first and json is indented)
{
"Id": 0,
"Value": {
Text: "Hello, World"
},
"Type": "Text",
"MessageState": 1
}
{
"Id": 1,
"Value": {
"Number":8
},
"Type":"Integer",
"MessageState": 1
}
{
"Id":0,
"Value":{
"Number":42
},
"Type": "Integer",
"MessageType": 2
}