-
November 22nd, 2005, 08:23 PM
#1
CSoket, Receive stops
Hi,
I did following
CSocket pSocket = new CSocket();
pSocket->Create();
pSocket->Connect("11.11.11.11","8000");
======================================
len = pSocket->Send("asdfa", 6); ------------> Seems working
len = 6
len = pSocket->Receive(pBuf, 20); -----------> Stops
What reason cause "Receive" stops?
Thanks,
-
November 22nd, 2005, 10:47 PM
#2
Re: CSoket, Receive stops
CSocket is designed to operate in "blocking" mode, this means it will wait until the requested operation completes, or an error occurs.
Specifically, in your example, it looks like the first call succeeds because there is at least 6 incoming bytes that are correctly received, then when you try to call Receive again, there are less than 20 more bytes waiting to be received.
To use non-blocking style sockets, look at using the CAsyncSocket class.
Be aware that the MFC implementation of these socket wrappers are not without their problems. They are fine to use for experimental, or learning purposes, but their use in commerical applications should be reviewed.
...the alternative to using these MFC socket wrapper classes is to use the Windows Sockets API calls, such as recv, etc.
Here is a page describing the API routines.
Hope this helps,
- Nigel
-
November 22nd, 2005, 11:14 PM
#3
Re: CSoket, Receive stops
Hi Nigel
Thank you very much. It helped me a lot. Could you give me an example about using "the Windows Sockets API calls" to conduct TCP/IP coomunication?
Thank you very much
-
November 22nd, 2005, 11:30 PM
#4
Re: CSoket, Receive stops
You're very welcome
Here is one of the best sites describing network programming that I've come across. There are a lot of articles describing how to use sockets, and there are also several examples there to get you started.
Hope this helps,
- Nigel
-
November 23rd, 2005, 03:06 PM
#5
Re: CSoket, Receive stops
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|