E
Erik
I'm implementing a program which uses a specific protocol to
communicate with other clients, but I was wondering how to implement
the protocol itself (in a well structured way). I already have a class
which handles the serialization and sending and receiving of messages.
So now I have to implement the protocol itself, but I'm not sure what
good way to implement this is. For example, is it a good idea to
implement the protocol steps in one function like this:
protocol(){
send req
recv response
if correct response
send file
else
send bye
}
or is it better to use some sort of state machine and let a function
handle the incomming messages:
handleMsg(msg){
if msg == req and state == 0:
do something
if msg == file and state == 1:
do something else
....
}
So my question is how do most programs implement there protocol?
Also, what is the best way to handle asynchrone messages (for example
sending
a msg while you also are waiting to receive a message)?
Thanks
Erik
communicate with other clients, but I was wondering how to implement
the protocol itself (in a well structured way). I already have a class
which handles the serialization and sending and receiving of messages.
So now I have to implement the protocol itself, but I'm not sure what
good way to implement this is. For example, is it a good idea to
implement the protocol steps in one function like this:
protocol(){
send req
recv response
if correct response
send file
else
send bye
}
or is it better to use some sort of state machine and let a function
handle the incomming messages:
handleMsg(msg){
if msg == req and state == 0:
do something
if msg == file and state == 1:
do something else
....
}
So my question is how do most programs implement there protocol?
Also, what is the best way to handle asynchrone messages (for example
sending
a msg while you also are waiting to receive a message)?
Thanks
Erik