Advice about function calling conventions when using sockets
-
27-10-2019 - |
Question
I plan to use sockets to make function calls between a client 32 bit application and a 64 bit application.
What would be the best scheme to call functions, pass variables and return parameters via the socket interface. I have control over both the client and the server code so I can implement anything.
I was thinking, to have the socket packet being made up of: - 1 word: length (# of characters) of the function name - string: the actual function name - 1 word: length (in bytes) of the function parameters - function parameters
Please let me know, what would be the most robust and extensible approaches. Maybe I can reuse principles used by calling conventions by compilers, web services or virtual machines.
Thanks in advance
Solution
I suggest that you use Protocol Buffers for the serialization:
http://code.google.com/apis/protocolbuffers/docs/reference/cpp/index.html
Tutorial:
http://code.google.com/apis/protocolbuffers/docs/cpptutorial.html
When you send the object to the other side, start with a length prefix (32bit int) which defines how many bytes you should read to get a complete protobuf message.