We help IT Professionals succeed at work.

Issue with Data Recv in Socket programming

fastnet5
fastnet5 asked
on
346 Views
Last Modified: 2013-12-14
Hi,

I am working on a client Application using a socket.I am getting the problem while receiving the data.The recv return value is not matching with the no of character received.For Ex
typedef struct {
  unsigned short len;
  unsigned long ref;
  unsigned char  data[65529];
} DATA_PCKT;

numBytes = recv(socketId, (char *)&recvPckt, sizeof(recvPckt),MSG_PEEK);
here numbytes return 77
dataLen = ntohs(recvPckt.len) - DatapcktHdrSz; = 71
int ii=strlen((char*)recvPckt.data); = 69.

It is triming first two charater.I don't know why ?
Please help

send func :
DATA_PCKT sendData;
	DatapcktHdrSz = sizeof(sendData.len) + sizeof(sendData.ref);
	
	memcpy(&sendData.data, message.c_str(), message.size());
	sendData.len = htons(message.size() + DatapcktHdrSz);
	sendData.ref = htonl((rand()*100000) + 2000);
numBytes =send(socketId, (char *)&sendData, ntohs(sendData.len), 0)==-1
 
recv function:
numBytes = recv(socketId, (char *)&recvPckt, sizeof(recvPckt),MSG_PEEK);
dataLen = ntohs(recvPckt.len) - DatapcktHdrSz;
	memcpy(message, &recvPckt.data, dataLen);
	int ii=strlen((char*)recvPckt.data);

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Author of the Year 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Dan.
I have one more query if you can help please.
I created a MFC Regular DLL(Dynamically Linked with MFC) .Now I have to register that DLL .When I tried to Register through command prompt using regsvr32 i got error.


untitled.bmp
CERTIFIED EXPERT
Author of the Year 2009

Commented:
You created a DLL that does not need to be registered.  That RegSvr32 procedure you've read about is used after you create COM objects, ActiveX controls and so forth.  I'd say more, but that is a completely different question and we're supposed to answer only one question at a time.  And anyway, a grade of "B" is not a great compliment...
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.