Code Comments
Programming Forum and web based access to our favorite programming groups.thanks a lot!! I just tried different ways, if I do the following rather than or Then, it is working fine. But I still don't quite understand the rationale, because I thought strlen(recvBuf)+1 already represents the packet length. 100 is the maximum length of the packet that I defined for the recvBuf variable. please advise. thanks!!
Post Follow-up to this messageOn 11 Jul 2004 22:50:14 -0700, Matt <jrefactors@hotmail.com> wrote: > thanks a lot!! > > I just tried different ways, if I do the following > > rather than > > or > > Then, it is working fine. But I still don't quite understand the > rationale, because I thought strlen(recvBuf)+1 already represents the > packet length. 100 is the maximum length of the packet that I defined > for the recvBuf variable. > No, how can strlen(recvBuf)+1 represent the packet length when strlen(recvBuf)+1 is called *before* you received the packet? At best strlen(recvBuf)+1 will be the length of the *last* packet you received not the packet you are *about* to receive. In any case recv does not need to know the packet length, you've got that wrong. It does need to know the size of the buffer you have given it (which is nothing to do with the packet length). In your case the size of the buffer is 100 bytes, so that is what you should put for the third argument. *After* you have called recv, then you have a packet, and then (depending on what you sent) is might be sensible to call strlen(recvBuf)+1 to find out how big the packet is. Although I think rVal will tell you the same information. But think about it, you cannot find out how long a packet is until *after* you have received the packet, that seems obvious. john
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.