Reputation: 2945
I'm getting ready to attempt my first project involving networked communications. This is just a tinker-toy app with the purpose of self-teaching - nothing mission-critical here. I will need two nodes to communicate with each other. One will be an Android platform, so I will be using Java. The other node will be a RaspberryPi running Debian Linux. While I COULD use Java on this end as well and maybe just use RPC, what I would LIKE to do is develop my own little implementation-agnostic TCP/IP "protocol" for the two to communicate, and let the each implement it however works best. What I mean by "protocol" is I want a standard set of messages to be passed back and forth, along with some values with each. E.g.:
"Protocol" Definition:
MESSAGE TYPE A (Float arg, Int arg)
MESSAGE TYPE B (Int arg)
MESSAGE TYPE C (Int arg, String arg, Int arg)
An example "conversation":
Node 1 Node 2
A(5.4, 4) --->
B(6) --->
<---- C(3, 'Hello', 0xFF)
B(5) --->
<---- A(43.0, 16)
So my questions are:
(1) Does the above even make sense? Do I need to clarify my intent? Provide more info? This is my first forray into networked communication between two running programs, so I may be way off-base in what I'm asking for. If I'm approaching this the wrong way, I'd be happy for better recommendations.
(2) How would I go about this? Do I just stuff one long string into a TCP packet? Is there a better way?
Thanks!
Upvotes: 0
Views: 121
Reputation: 2720
You only need to fill a buffer with the data you want and then learn how to open and send data through a TCP socket. The kernel will handle how to arrange the payload and how to control the TCP stream. On the server end, you must learn how to listen on a TCP socket and read incoming data.
Upvotes: 1