Dealing with multiple protocols

Jun 3, 2013 at 12:46 AM
Edited Jun 3, 2013 at 12:54 AM

I need to implement an UDP server which can handle multiple protocols, these binary requests could have fixed length headers while others could have start/end delimiters, and there could be even more protocols added in the future, these are all sent to the same socket and the protocols are fixed so I can't change them.

So, given a binary stream sent via UDP, I need to be able to "choose" which receive filter will parse it and call its corresponding commands, but I haven't figured out an easy way do this, is there an standard way to do this? or do I have to write my own receive filter?

Thanks in advance!
Jun 3, 2013 at 2:04 AM
Could you tell me how to choose receive filter in the server side? It is the key to answer your question.
Jun 4, 2013 at 3:09 AM
Edited Jun 4, 2013 at 3:10 AM
Well, it turned out that I needed to have this done before I could even think about it so I ended up implementing my own Receive Filter, I don't have the code right now but what it does is basically:
if it's protocol "A" then
    myProtocol = "A"
else if it's protocol "B" then
    myProtocol = "B"
For instance, one protocol has a fixed header length while another protocol has start/end delimiters, I can differentiate them by checking the first byte of the binary request, then I set a different command key string according to the received protocol, it seems to work just fine.

Thanks for developing SuperSocket!
Jun 4, 2013 at 3:32 AM
Good, you can design a SwitchReceiveFilter to detect protocol, when you find the mark byte, then you should set the NextReceiveFilter of the switch filter with the different protocols' receive filters.
Jul 19, 2013 at 7:11 PM

Is there any sample on how to implement the SwitchReceiveFilter?

Jul 31, 2013 at 3:25 AM
Yes, there is a sample project named SwitchReceiveFilter in the QuickStart in the source code of master branch.