Sockets and buffer size

This is a discussion on Sockets and buffer size within the Linux Programming forums, part of the Platform Specific Boards category; I'm writing a C++ app that uses sockets and I have no problem sending an recieving, but am having trouble ...

  1. #1
    Registered User Joe Monti's Avatar
    Join Date
    Feb 2003
    Posts
    20

    Sockets and buffer size

    I'm writing a C++ app that uses sockets and I have no problem sending an recieving, but am having trouble separating the differnt types of messages i'm sending.

    I have several classes from which I need to send data using overloaded stream operators.

    when I say
    Code:
    socket << myObject;
    ...
    operator<<(Socket &socket, myObject mo) {
    	socket << mo.myInt;		// 0
    	socket << mo.myString;		// "hi world"
    }
    I recieve this: "0hi world", but I want to recieve "0", then "hi world".

    Is there any way to force the sockets to read and write in sync? without encoding value delimiters or forceing fixed-width data.

    I was thinking encoding delimiters may be more efficient at least on the per-object transmissions, but there will still be a point when I need to force read and write to sync between sending objects. (this is also multi-threaded with lots of user input jumping around)

    fixed-width data is out of the question becase there are so many types of clasess with so many types of data that need to be sent.

    Thanks!
    - Joseph Monti
    __________________
    This message is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more info visit http://joe.tgpr.org/

  2. #2
    Registered User Joe Monti's Avatar
    Join Date
    Feb 2003
    Posts
    20
    Thanks. I will probably use some kind of encoding to format each object, but I am still concerned that more than one object will read/write at a time.

    There should be some way to signal the buffer dynamically, rather than specifying by fixed width.

    The problem is I dont know these sockets too well. And I dont know if its being buffered on the sending or recieving end. Is there somthing I can set on the socket for this?

    I've looked through the <sys/socket.h> header and around on Google, but I couldn't find anything to describe in detail what i'm looking for.

    Any suggestions?
    - Joseph Monti
    __________________
    This message is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more info visit http://joe.tgpr.org/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer over sockets
    By adrians in forum C Programming
    Replies: 3
    Last Post: 03-02-2009, 12:56 AM
  2. Jumbo Frames - sort of working
    By bj00 in forum Networking/Device Communication
    Replies: 1
    Last Post: 07-23-2007, 11:29 AM
  3. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 06:32 AM
  4. Sockets
    By Twiggy in forum Windows Programming
    Replies: 8
    Last Post: 03-31-2003, 09:01 AM
  5. Understanding Sockets
    By minesweeper in forum Windows Programming
    Replies: 3
    Last Post: 02-06-2003, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21