forceful terminate socket Recv . RRS feed

  • Question

  • Hi,

    I am using 2005 MFC. I have used 2 two header files..

    #include "winsock2.h"

    #include "connmgr.h"


    I am sending the request to the socket  through this code

    SentBytes= send(Sock,(char*)Request,700,0);

    Request contain the server URL and other http headers...

    and getting the response through this code.

    RecvBytes = recv(Sock,Response,500,0);


    it work fine, but i want to know that if the server is down. or i point my application  to the unknown server then  my application stuck forever on recv  method of socket. how i overcome that ????  no response i get  through recv i have tried this for 5 minute ..... how to overcome this deadlock?

    Want forceful termination of socket  if didnt recieve any response in 1 minute.......... any idea or suggestion to do this???



    Tuesday, May 1, 2007 10:25 AM


All replies

  • Hi,
    you can easily use :Tongue Tiedelect() with a timeout value. Take a look here.
    That should give you all the information needed.


    Wednesday, May 2, 2007 6:41 AM
  • Thanks Kaldor,

    I dont have much concept of socket programming.....

    I have tried this.

    struct timeval* t;

    t = new timeval;

    t->tv_sec = 300;

    t->tv_usec = 300*60;

    int a = select(NULL,NULL,NULL,NULL,t);


    if ((a == SOCKET_ERROR)|| a == 0)


    a =WSAGetLastError ();


     but it give error 10022..... any option or parameter i m missing???  i just call select function before recv   function.......




    Thursday, May 3, 2007 10:25 AM
  • Hi Salman,


    Sorry, but your question is off topic here since this is the forum with smart device development.

    Move to Visual C++ General forum. Thanks!

    Tuesday, May 8, 2007 2:25 AM
  •  Salman Maredia wrote:

    I dont have much concept of socket programming.....

    Please check this page out to get basic concept of socket programming:


    If you have further questions, take win32 network programming newsgroup as home, thanks.


    hope it makes sense


    Tuesday, May 8, 2007 8:19 AM