Thread: Sockets programming

  1. #1
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193

    Sockets programming

    I'm having some doubts about socket programming that are burning my head and delaying my learnings about sockets.
    Is it better to write into a socket or to use the function send?
    When sending trough sockets, I was told that the data it's beeing sent may be divided into chunks, how does this work? I'm triying to undestand this to assemble the data at the end.
    Thanks in advance
    Last edited by lautarox; 07-28-2010 at 08:03 AM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    When sending trough sockets, I was told that the data it's beeing sent may be divided into chunks, how does this work?
    There are a lot of factors that influence what the kernel does - and for a variety of reasons, it may choose to only send part of your data at once (and of course, the larger the chunk of data you send, the more likely this s). That's why send returns the number of bytes that were actually sent before the kernel stopped. If it doesn't send everything, increment your pointer by that amount (so that it now points to the beginning of the unsent portion), and try sending it again. Beej's guide to networking has a short section on this.

    I'm triying to undestand this to assemble the data at the end.
    It shouldn't affect the way you read data. Just keep reading from the socket and the data will come through in a stream. TCP takes care of ordering packets correctly, etc.

    Is it better to write into a socket or to use the function send?
    My guess is it's at the very least 'best practice' to use send, as it's made specifically for that purpose. I've never personally tried writing into a socket as a file, but on *nix sockets really are files, and it's my understanding that it works. I don't know if there are any risks, such as not finding about unsent data.

  3. #3
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    Location
    Argentina
    Posts
    193
    Thanks for your reply, I'll check what was sent and recv and organize the data

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to poll sockets?
    By 39ster in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-22-2008, 01:43 PM
  2. multiple UDP sockets with select()
    By nkhambal in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-17-2006, 07:36 PM
  3. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  4. Raw Sockets and SP2...
    By Devil Panther in forum Networking/Device Communication
    Replies: 11
    Last Post: 08-12-2005, 04:52 AM
  5. Starting window sockets
    By _Cl0wn_ in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2003, 11:49 AM