how to block a socket indefinitely

This is a discussion on how to block a socket indefinitely within the Networking/Device Communication forums, part of the General Programming Boards category; Hi everybody, When a socket is created, by default it is a blocking socket. Under blocking mode socket I/O operations, ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    35

    how to block a socket indefinitely

    Hi everybody,

    When a socket is created, by default it is a blocking socket. Under blocking mode socket I/O operations, connect and accept operations all block until the operation in question is completed.
    I want to receive data periodically from a client. That is, the first time I receive data the socket is blocked in the accept function but the next time is not blocked anymore and I want that it waits for the next incoming data.
    I used the ioctlsocket function after the accept function this way:
    Code:
    AcceptSocket = SOCKET_ERROR;
    		while (AcceptSocket == SOCKET_ERROR)
    		{
    			AcceptSocket = accept(socketInTCP, NULL, NULL);
                            ioctlsocket=(socketInTCP, FIONBIO, &imode);
    		}
    but I get this error message at the ioctlsocket function: 10093, and I read that is because the WSAStartup() was wrong but it isn't so.

    Can you help me
    thank you very much.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    One way to do it would be to use select() or create a separate thread.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    35
    can you explain me a little bit more? I think I can use this select function to have a server with concurrent clients but I haven't this. I have a server for an iterative client.

    thank you

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    You may want to try this forum.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,773
    Moved to Networking/Device Communication forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  3. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  5. pointers
    By fanaonc in forum C Programming
    Replies: 3
    Last Post: 11-17-2001, 01:18 AM

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