Click here to Skip to main content
15,886,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am writing a client server application in C++. These applications talk to each other using TCP sockets. I want to use two application protocols to communicate. One binary and one text based protocol. There are two ways. I can use two connections for each protocol or can use the same connection for both the protocols.

What are the pros and cons of using same connection for the two protocols?

What I have tried:

NA
What are the pros and cons of using same connection for the two protocols?
Posted
Updated 1-Dec-16 20:54pm

1 solution

If you use a single connection for two protocols you would have strictly speaking only one protocol because your client has to decide which kind of data handling has to be used and this decision is defined by the protocol.

If the two protocols are not standard ones but defined by you just combine them into one. Each protocol usually has some kind of header that contains information about the following data. Define such a header that indicates if the data are text or binary.

When using standard protocols you can do the same. Define your own protocol with a header that specifies the type of data.

Using a single connection should be simpler than using two connections regarding the code. Creating and parsing a header requires only a few lines of code while handling two connections is more complex.

So I would go for this solution according to the "Keep it simple" rule.

However, there may be situations where using two connections might be more appropriate. See for example FTP which uses a control and data connection.
 
Share this answer
 
Comments
CPallini 2-Dec-16 2:59am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900