Thread: Sending 2 things simultaniously to same client.

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    80

    Sending 2 things simultaniously to same client.

    Hi, I'm having trouble figuring out how to do two things "simultaniously" over the same connection. Say I want to send 2 files to the same client or send 1 file and some text messages. The problem is that I use the send function to do both so I can't make sure that the client recv doesn't mix the file info with the text message (I'm using winsock). An example of the behavior I need is something similar to msn messenger (or any other chat software), there you can chat and send a file at the same time. Since I'm sending both messages and files with the send function, there is no way for the client recv function to know the difference because all it does is receiving the next bytes available over the connection.

    I would really appreciate any help I can get because I don't see any solution at all.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You can wrap your messages in some internal protocol
    ((MesType,MesLen,MesBody))
    and parse these buffers on the receiver side applying actions according to MesType
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Ok thanks. Is it a bad idea to let the first or first few bytes received from each call identify the type, or is that good enough for most purposes? But what if not all info gets extracted in one call, due to some connection problem or some kind of buffer problem, then the next piece of information won't be the identification bytes. How do I solve this? I really don't understand internal socket buffers or whatever they are called.
    Last edited by antex; 03-26-2007 at 05:36 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Define some pattern for message start and message end (called start marker and end marker)
    in my sample it was "((" and "))"
    check for these markers before you start parsing the rest and after you finished parsing

    if markers don't match - start scanning the stream till you find the start marker...

    It you use TCP and not UDP you should not have problems with loosing data or receiveing unordered data...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Thank you very very much!

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by antex
    Ok thanks. Is it a bad idea to let the first or first few bytes received from each call identify the type, or is that good enough for most purposes? But what if not all info gets extracted in one call, due to some connection problem or some kind of buffer problem, then the next piece of information won't be the identification bytes. How do I solve this? I really don't understand internal socket buffers or whatever they are called.
    Why not just make another connection to the host? Imagine trying to have three conversations on a single phone line. You could come up with some complicated protocol to allow multiple people to all talk on the same line, but WHY?

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by brewbuck View Post
    Why not just make another connection to the host? Imagine trying to have three conversations on a single phone line. You could come up with some complicated protocol to allow multiple people to all talk on the same line, but WHY?
    BTW - I think that is what Messagenger ICQ etc do, You can check the number of open ports on your comp when you start simple conversation in Messager, and compare it to the number of open ports when the file transfer starts... 1 port should be added to the list
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Well, I didn't think about that at all, but that seem to be a good option and far easier to program too. Thank you both for your replies! I really appreciate you help!

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    You could try sending the text as OOB data, which is handled seperately from the normal data stream.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by abachler View Post
    You could try sending the text as OOB data, which is handled seperately from the normal data stream.
    A Google search for "TCP OOB" turns up zillions of examples why using OOB transmission is a bad idea, not universally supported, not guaranteed to work, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-24-2008, 06:05 AM
  2. server client problem
    By rudeboy in forum Networking/Device Communication
    Replies: 5
    Last Post: 05-17-2008, 12:41 AM
  3. sending binaries files between server and client
    By nacho4d in forum C Programming
    Replies: 12
    Last Post: 01-31-2008, 01:54 AM
  4. Replies: 2
    Last Post: 11-23-2007, 02:10 AM
  5. Server Client Messaging Program
    By X PaYnE X in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-04-2004, 05:20 PM