Main Page | Report this Page
.NET DotNet Forum Index  »  Visual C++ Forum  »  Problem with recv() using c++...
Page 1 of 1    

Problem with recv() using c++...

Author Message
Kevin...
Posted: Wed Oct 14, 2009 1:37 pm
Guest
Hi All,

Ive been writting a program that connects to servers then sends a http
request using send and that recieves html code back.
It works most of the time however sometimes the recv command waits a too
long when there is nothing left to recieve.

some of my code is
do{
recvint = recv(sock, recvbuf, 1000, 0);
printf("\necvint %d:\n", recvint);
printf("%s\n", recvbuf);
} while( recvint > 0 );

Is there any way to stop the recv after 5 seconds? It seems to wait until
the socket is closed by the server which means that the program waited all
night because one server doesnt close connections.

If you want any more info let me know.

Thanks

Kevin
 
Ben Voigt [C++ MVP]...
Posted: Thu Oct 15, 2009 6:35 pm
Guest
WsaRecv w/OVERLAPPED + (Msg)WaitForSingle(Multiple)Object(Ex) with a
timeout.

Or refactor using non-blocking ioctl and select (or WsaEventSelect or
WsaAsyncSelect)


"Kevin" <mymsnmessengeraccount at (no spam) hotmail.com> wrote in message
news:AD003FEE-800A-4855-8DB3-9A35FED0CC8F at (no spam) microsoft.com...
Quote:
Hi All,

Ive been writting a program that connects to servers then sends a http
request using send and that recieves html code back.
It works most of the time however sometimes the recv command waits a too
long when there is nothing left to recieve.

some of my code is
do{
recvint = recv(sock, recvbuf, 1000, 0);
printf("\necvint %d:\n", recvint);
printf("%s\n", recvbuf);
} while( recvint > 0 );

Is there any way to stop the recv after 5 seconds? It seems to wait until
the socket is closed by the server which means that the program waited all
night because one server doesnt close connections.

If you want any more info let me know.

Thanks

Kevin

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Kevin...
Posted: Thu Oct 15, 2009 7:17 pm
Guest
Hi Ben,

Thanks for your reply.

just as you posted that reply i had just found out about

setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&n,sizeof(int));

which seems to have fixed the problem but have not tested it properly yet.
i will try wsarecv to see how it works.

Thanks
Kevin

"Ben Voigt [C++ MVP]" <bvoigt at (no spam) newsgroup.nospam> wrote in message
news:989A6F97-38E0-4F68-86AF-5399183A8FC4 at (no spam) microsoft.com...
Quote:
WsaRecv w/OVERLAPPED + (Msg)WaitForSingle(Multiple)Object(Ex) with a
timeout.

Or refactor using non-blocking ioctl and select (or WsaEventSelect or
WsaAsyncSelect)


"Kevin" <mymsnmessengeraccount at (no spam) hotmail.com> wrote in message
news:AD003FEE-800A-4855-8DB3-9A35FED0CC8F at (no spam) microsoft.com...
Hi All,

Ive been writting a program that connects to servers then sends a http
request using send and that recieves html code back.
It works most of the time however sometimes the recv command waits a too
long when there is nothing left to recieve.

some of my code is
do{
recvint = recv(sock, recvbuf, 1000, 0);
printf("\necvint %d:\n", recvint);
printf("%s\n", recvbuf);
} while( recvint > 0 );

Is there any way to stop the recv after 5 seconds? It seems to wait until
the socket is closed by the server which means that the program waited
all night because one server doesnt close connections.

If you want any more info let me know.

Thanks

Kevin

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


 
Ben Voigt [C++ MVP]...
Posted: Thu Oct 15, 2009 7:42 pm
Guest
That also should work, as long as you only need a receive timeout. If you
need to timeout anything else (like connect, disconnect, etc) try with
OVERLAPPED.

"Kevin" <mymsnmessengeraccount at (no spam) hotmail.com> wrote in message
news:ODa545fTKHA.3404 at (no spam) TK2MSFTNGP04.phx.gbl...
Quote:
Hi Ben,

Thanks for your reply.

just as you posted that reply i had just found out about

setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&n,sizeof(int));

which seems to have fixed the problem but have not tested it properly yet.
i will try wsarecv to see how it works.

Thanks
Kevin

"Ben Voigt [C++ MVP]" <bvoigt at (no spam) newsgroup.nospam> wrote in message
news:989A6F97-38E0-4F68-86AF-5399183A8FC4 at (no spam) microsoft.com...
WsaRecv w/OVERLAPPED + (Msg)WaitForSingle(Multiple)Object(Ex) with a
timeout.

Or refactor using non-blocking ioctl and select (or WsaEventSelect or
WsaAsyncSelect)


"Kevin" <mymsnmessengeraccount at (no spam) hotmail.com> wrote in message
news:AD003FEE-800A-4855-8DB3-9A35FED0CC8F at (no spam) microsoft.com...
Hi All,

Ive been writting a program that connects to servers then sends a http
request using send and that recieves html code back.
It works most of the time however sometimes the recv command waits a too
long when there is nothing left to recieve.

some of my code is
do{
recvint = recv(sock, recvbuf, 1000, 0);
printf("\necvint %d:\n", recvint);
printf("%s\n", recvbuf);
} while( recvint > 0 );

Is there any way to stop the recv after 5 seconds? It seems to wait
until the socket is closed by the server which means that the program
waited all night because one server doesnt close connections.

If you want any more info let me know.

Thanks

Kevin

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Wed Dec 09, 2009 7:41 am