Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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

  2. #2
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    145

    Post

    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.

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Location
    Argentina
    Posts
    4
    Quote Originally Posted by Schmidt View Post
    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.
    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.

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •