Thread: Sockets... Sending Binary Data. Please help

  1. #16
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    I specify a timeout time of 1 second... if it hits that, then i break out of the receieve loop.
    That seems a wee dangerous, should your connection slow temporarily.
    If your situation is simple, you might not want to bother with the complexity of select() - just keep using recv(). For blocking sockets (the default) recv() will return 0 when the connection is closed, and -1 on any error. (Connection loss, etc.) Having the server close the connection after transfer seems it would suffice.
    Should you need to keep the connection open for other data, then you should send the file's size before the file itself, so the client knows how much to recv.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  2. #17
    Registered User
    Join Date
    Jan 2007
    Posts
    38
    What I have done is:

    - I still use select but only to make sure there is data to be sent (to be same).. and this is before the recv loop

    - To break out of the loop I send the file size expected, and when the amound of data recv == to what is expected i break out of the loop and return success message, if this is not true at any iteration of the loop I use select to check that there is still data to be sent.

    For some reason If there is no data to be send the recv does not return 0 or an error code.. it just hangs.

    Does the socket that is sending the data need to be closed in order to get out of the recv loop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending data - line by line?
    By tuckker in forum C Programming
    Replies: 0
    Last Post: 02-21-2009, 09:31 PM
  2. Changing header data in binary file
    By neruocomp in forum C Programming
    Replies: 8
    Last Post: 11-14-2008, 07:30 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Sockets: send/receive continuous stream of data?
    By diddy02 in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-09-2008, 12:52 AM
  5. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM