Winsock. What's the right way to make a blocking send()?

This is a discussion on Winsock. What's the right way to make a blocking send()? within the Windows Programming forums, part of the Platform Specific Boards category; I need that when I call send(), my application does not reach the next line until that send is completed. ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    55

    Winsock. What's the right way to make a blocking send()?

    I need that when I call send(), my application does not reach the next line until that send is completed. I've been doing it by calling select(), but is there any other way to do it?

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    use asynchronous or non-blocking sockets
    http://tangentsoft.net/wskfaq/articl...trategies.html

    I think this would go in the "Networking/Device Communication" section
    Last edited by h_howee; 06-15-2007 at 11:59 AM.

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    Nono, I WANT to block... I want blocking sockets... But the recv() is the only one that is actualling blocking, send() is not.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Why would you want that?

    I've been doing it by calling select(), but is there any other way to do it?
    if you want blocking sockets, don't use select

    when recv blocks, its usually waiting for data but what is there for send to do? it just sends the data out and returns

    were you unable to send all the data at once? if so...
    http://beej.us/guide/bgnet/output/ht...t.html#sendall

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    55
    I just need the application that calls send() to stop until the recv() receives all the data, for different reasons...

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Make the application that calls send() call recv() directly afterwards and wait for the application that calls recv() to send a confirmation using send().

    There's no other way.

    Well, there might be other ways, but they will typically be more complex.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    There is no other way. send() will not reliably block, it isnt supposed to. I suppose you could hack the berkely sockets code under linux to make the TCP/IP protocol implement some sort of blocking sequence, but then it would just be the same as having a recv() after the send to wait for a confirmation and might break the protocol, or at least make it under-perform.

    Quote Originally Posted by manugarciac View Post
    I just need the application that calls send() to stop until the recv() receives all the data, for different reasons...
    perhaps if you shared the reasons we might be able ot give you a more specific solution.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 07:32 AM
  2. nonblocking send need help
    By sleith in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-27-2008, 10:51 PM
  3. How to initialize a non blocking socket using only winsock library
    By *DEAD* in forum Networking/Device Communication
    Replies: 4
    Last Post: 01-18-2008, 06:03 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Is there a way to send floats through Winsock?
    By jimboob in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-29-2004, 01:38 AM

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