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

  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,895
    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,195
    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.

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, 08: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, 07:03 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09: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