Results 1 to 4 of 4
i am doing a project where 2 clients connect to server and communicate (chat) and transfer data one after other using sockets. i have working code for this in C ...
- 02-25-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 1
Parallel data transfer using Sockets
i am doing a project where 2 clients connect to server and communicate (chat) and transfer data one after other using sockets. i have working code for this in C language
Now our main aim is to create a communication link where two clients transfer multiple streams data parallely. To be more precise i want to transfer images files and audio files parallely at same time, so is it possible to send data parallely using one socket connection? or i need to add an extra thread
Is there any way to achieve this, can anyone suggest me some logic or tips
Thanks
Ranjeet
- 02-26-2011 #2Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
I advise you to establish two different connections. Anyway you write your code, it would be easier to use a second thread with another connection for file transfer, because if you mix your data and send, a receiver will not be able to parse this garbage.
- 02-26-2011 #3Just Joined!
- Join Date
- Oct 2008
- Location
- Argentina
- Posts
- 4
I'd do as Schmidt sais. Besides, a socket and a thread are not that expensive anyway. Unless you are programming in an embedded device or such, go for that. It's more trouble thinking your code for it to manage multiple transfers in one socket than simply starting a new connection within a thread each time you need another paralell data transfer.
- 02-26-2011 #4Just Joined!
- Join Date
- Dec 2009
- Location
- California
- Posts
- 68
If you want true parallel transfer of images and audio files from a single client, you will, by definition, need to use a separate thread. You could implement some sort of pseudo-parallel transfer by maintaining a list of the files that you are transfering and sending a chunk of each one in a loop. Either way, you will need to add code to multiplex/demultiplex the stream so that you write the stuff to the correct file on the other end. The other poster talks about "garbage", but that's not true - you just need a protocol. What I would do is get a list of the files and stick them in an array. when you first open the connection, send the list of files and construct the same array on the receiving side. Each time you put data into the socket, set the first byte of the data stream to the index into the array. The receiving side would read that first byte to determine which file to place the data into.
As for supporting multiple clients simultaneously, I think that is trivial - when the connection comes in, just fork to service that request.


Reply With Quote
