Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone.
I have the following question. I have managed to have a TCP link and I can send/receive a CArchive via CSocket. Everything works just find. But not my question is. Can I send different CArchives data via the TCP? What I mean is, how would the receiving end now what kind of data is send so to use the correct structure?
The idea is, that now, I have created a very big class, containing all of the possible data I may need to send. But this is impractical. Is there any way this to be done, using CArchive and CSocket?


Xumepoc
Posted
Comments
Richard MacCutchan 17-Jan-14 4:33am    
Each end of the socket must know the structure of the data.
xumepoc 17-Jan-14 5:02am    
So basically it is not possible. In order to do that, I have to have a second connection via which I have to tell the other side what kind of data to expect. The thing is we are talking about time critical data, so how to be sure that the indication will always arrive before the data connection
Richard MacCutchan 17-Jan-14 5:20am    
You cannot, for obvious reasons, pass a stream of data to a program and expect it to be able to understand the content. So you either have a connection point that can decode the data, or it stores the data somewhere for later processing by another application. I'm not sure I understand your second question, but the usual way of dealing with this is to have a header on each data packet that indicates its type.
xumepoc 17-Jan-14 5:26am    
Well my question was if I can have a second TCP on different port to only indicates that the next incoming data is of data1 let say.

If I include the header, it will be part of the data structure itself? So on the deserialization with CArchive the first thing it will do is get the header, correct?
Richard MacCutchan 17-Jan-14 5:37am    
Yes, you can have as many ports as you require. However, it may be more efficient to have a single port that then paases off the data to the appropriate function for processing.

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