Query related to DisconnectEx?

This is a discussion on Query related to DisconnectEx? within the Networking/Device Communication forums, part of the General Programming Boards category; Hi How do i make my server application listen for new client connection. I cannot use DisconnectEx() as this function ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    17

    Arrow Query related to DisconnectEx?

    Hi

    How do i make my server application listen for new client connection.

    I cannot use DisconnectEx() as this function is supported only by WinXP.

    So what i have done is that when ever the client socket is closed, i also close my server socket & then reopen again to listen for new client.

    In my project there can be only one client at a time.

    Is my approach correct?
    Is there any other wasy out?

    Regards
    dp_76

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    There is no need to disconnect your bound server socket when the client disconnects. Just keep accepting connections in a loop:
    Code:
    for(;;)
    {
      accept();
      // start new thread to handle new connection
    }

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    17
    I m not getting what u r trying to say.

    Can u post some code that does it?

    Waiting for suggestions

    Regards
    dp_76

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    What bithub is saying is that when your application accepts a connection it is still listening for more connections, you can call accept again on the listening socket.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    17
    Hi
    Thanx for ur suggestions.

    I understand that the server is still listening for more connections, but in my application it gives errors.

    If i do as mentioned in quotes will it have any ill effect on my application.

    "So what i have done is that when ever the client socket is closed, i also close my server socket & then reopen again to listen for new client."

    Waiting for suggestions

    Regards
    dp_76

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Well there are two sockets, the one which you passed to accept() which is the socket in the listening state and the socket which accept() returns which is the socket that handles the server connection. When you've finnished with the server you can close the socket that was returned by accept() and call accept() again on the same socket that you origionally passed to accept()
    If your listening socket is none-blocking and there are no connections available you will get a SOCKET_ERROR and a call to WSAGetLastError() will return WSAWOULDBLOCK letting you know that you can still keep calling accept() on that socket untill there is a connection to accept.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. query problem
    By arian in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 01:49 PM
  2. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  3. Problem in when I run insert query
    By Bargi in forum Windows Programming
    Replies: 1
    Last Post: 05-09-2007, 10:46 PM
  4. Replies: 1
    Last Post: 09-18-2005, 09:06 PM
  5. Query related to recv()?
    By dp_76 in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-16-2005, 07:25 AM

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