difference between CSocket and CAsynSocket Recieve Call
-
What is the difference between CSocket and CAsyncSocket Accrding to MSDN CSocket is a blocking socket and CAsynSocket is a non blocking socket from it what i understood that for example if u make a call on CSocket Recieve it will not return untill u get the whole data (which is wrong when data is on average > 5 k u have to make multiple recieve call to fetch the whole data) but in case of CAsyncSocket u will have to loop to get whole data . but another joke written in MSDN is that one should not make multiple recieve calls in OnRecieve while using CSocket::Recieve cauz CSocket is internally dooing looping to recieve whole data. but with single call u cannot get the whole data atonce. so result of it's is that CSocket becomes useless after transferring 40 , 50 k data on average. so can anybody explain this scneriao . what is the best way to recieve data in OnRecieve and what socket should i use CSocket or CAsyncSocket. Note:i am writing a Video streaming software so server on average sends me data range from 5 to 15 k /sec .what i do in OnRecieve is asfollows do//i am using CSocket { res=Receive(ptr,lLength);//where ptr is buffer of size of incoming data if(res==SOCKET_ERROR) { Close(); break; } ptr+=res; total+=res; } while(total
-
What is the difference between CSocket and CAsyncSocket Accrding to MSDN CSocket is a blocking socket and CAsynSocket is a non blocking socket from it what i understood that for example if u make a call on CSocket Recieve it will not return untill u get the whole data (which is wrong when data is on average > 5 k u have to make multiple recieve call to fetch the whole data) but in case of CAsyncSocket u will have to loop to get whole data . but another joke written in MSDN is that one should not make multiple recieve calls in OnRecieve while using CSocket::Recieve cauz CSocket is internally dooing looping to recieve whole data. but with single call u cannot get the whole data atonce. so result of it's is that CSocket becomes useless after transferring 40 , 50 k data on average. so can anybody explain this scneriao . what is the best way to recieve data in OnRecieve and what socket should i use CSocket or CAsyncSocket. Note:i am writing a Video streaming software so server on average sends me data range from 5 to 15 k /sec .what i do in OnRecieve is asfollows do//i am using CSocket { res=Receive(ptr,lLength);//where ptr is buffer of size of incoming data if(res==SOCKET_ERROR) { Close(); break; } ptr+=res; total+=res; } while(total
I would try to stay away from CSocket and CAsyncSocket (I have ran into lots of problems with both).. If you use standard WinSock and stay away from those wrapper classes it would be much easier. Here is a example of how I might do the loop..
// This would keep looping until all the data is read, or a error occures.
char buff[4096];
int nRec;
while(nRec = recv(client,buff,sizeof(buff),0))
{
// Error and its not WSAEWOULDBLOCK
if((nRec == SOCKET_ERROR) && (nRec != WSAEWOULDBLOCK))
{
// Clean up and exit. (We have a problem)
// You could do WSAGetLastError() to figure out
// what exactly is happening.
}
else // Every thing is fine and dandy, keep looping until done.
{
// Store your info in this part
}
}Hope this helps.. Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
I would try to stay away from CSocket and CAsyncSocket (I have ran into lots of problems with both).. If you use standard WinSock and stay away from those wrapper classes it would be much easier. Here is a example of how I might do the loop..
// This would keep looping until all the data is read, or a error occures.
char buff[4096];
int nRec;
while(nRec = recv(client,buff,sizeof(buff),0))
{
// Error and its not WSAEWOULDBLOCK
if((nRec == SOCKET_ERROR) && (nRec != WSAEWOULDBLOCK))
{
// Clean up and exit. (We have a problem)
// You could do WSAGetLastError() to figure out
// what exactly is happening.
}
else // Every thing is fine and dandy, keep looping until done.
{
// Store your info in this part
}
}Hope this helps.. Rob Whoever said nothing's impossible never tried slamming a revolving door!
But is it possible to get OnReceive , OnClose like event notifications using WINSOK , can u refer me some good code regarding this. No Worries!
-
But is it possible to get OnReceive , OnClose like event notifications using WINSOK , can u refer me some good code regarding this. No Worries!
Yep you can get all those notifications.. Look around in CodeProject under Internet & Network there are quite a few articles from basic to advanced.. I will dig through my favorites when I get into work and email you some URL's with examples and good reading.. Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
But is it possible to get OnReceive , OnClose like event notifications using WINSOK , can u refer me some good code regarding this. No Worries!
Here is another good WinSock site.. I thought I had more links at work but I don't.. Anyway between Codeproject's Internet & Network area and the following link you shouldn't have many problems converting over to WS.. http://www.sockets.com/ Rob Whoever said nothing's impossible never tried slamming a revolving door!
-
Here is another good WinSock site.. I thought I had more links at work but I don't.. Anyway between Codeproject's Internet & Network area and the following link you shouldn't have many problems converting over to WS.. http://www.sockets.com/ Rob Whoever said nothing's impossible never tried slamming a revolving door!
thanx for ure reply.Some One has told me that BSD sockets are best of all , what u think abt it.cauz i now that CAsyncSocket is also a wrapper on WINSOCK , if that has problem how can i write a better wrapper than that , specially when u have limited time. No Worries!
-
thanx for ure reply.Some One has told me that BSD sockets are best of all , what u think abt it.cauz i now that CAsyncSocket is also a wrapper on WINSOCK , if that has problem how can i write a better wrapper than that , specially when u have limited time. No Worries!
Strangely enough, I never found any problem with CSocket. [Edit] I was able to send/receive data over 4 mega bytes using CSocket. [/Edit] But I don't have a simple sample program for you. If you don't mind reusing existing code, maybe you can check out this article[^], which does a lot more than you need. [Edit] You will have to use it in both of your programs (client and server) [/Edit][
My articles and software tools