I have an application where I have to send Signals and Data between two entities.
Which way is best practice and why?
- Open 4 sockets, 2 for signals in both directions and 2 for data in both directions
- Open 2 sockets each for data and signals
- Just open 1 socket and filter for signals and data
First of all sockets are full-duplex, i.e. you don’t need a separate socket (connection) for sending and receiving.
Secondly, it’s hard to tell without going into more details. However knowing the history of HTTP (one connection for commands/headers and data) and FTP (separate connections for commands and data) seems like HTTP designers made a better choice. Two connections is more code to maintain, also some firewalls don’t like hanging, idle FTP command connection when large portions of data are transferred.
So, go for one connection, it’s easy to distinguish between signals and data (flag, header, etc.) Also incoming and outgoing channel is completely orthogonal.