You must separate the socket class from the three protocol handlers - do not have methods for processing text and binary data on Socket, or you inadvertently encourage people to mix and match data types on the same socket, which is clearly not what you want.
Your socket should provide simple functions of connecting / disconnecting, transmitting and transmitting data, and decoding and encoding of the sent / received data is then performed in another object, probably selected from 3 new classes (one per protocol).
In general, I doubt the use of text data. This is inefficient compared to almost any serialization library that you could name. You can trade a little extra debugging for a lot of hard-written data analysis and error checking code and an accompanying malfunction in the processor cycle. If the text data is simple enough (not really structured, such as XML), then this causes fewer problems.
Protocol 2. can be implemented using UDP rather than TCP if status information is not critical. This is less than what you would need to do.
source share