user1255454
user1255454

Reputation: 699

Multiplexing data over socket

Basically I'm trying to have 2 - 3 file transfers from the same socket BUT all of them at the same time and yet not to interrupt messages sent back and to client/server.

Similar to a chat program between 2 people and 3 file transfers occurring.

I'm trying to avoid opening up 2 or more streams.

I want everything to occur asynchronously - still talk and transfer all 3 files at the same time ; not one after another.

How would my protocol look like? I can't think of this.

Upvotes: 1

Views: 1123

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409186

If you really want to do the packet switching yourself, I recommend a queue: Put packets that needs to be sent in one end, and in the other end you take packets and do the actual wire transfer.

For the packets that go over the wire, you need a type (file transfer or chat), a destination (where to put the file, or who you're chatting with), and the actual packet data.

On the receiving side you need to keep track of all recipients, chat and file transfers. When receiving a file transfer for destination X you save it to file X, if you receive a chat message for person Y you send the message on to person Y.

Upvotes: 3

Related Questions