Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using UDP Server which receives data through port 50001. I used wireshark to monitor the data. Here the data what i receive in UDP server buffer and what data is showing in wireshark is not matching fully . but some places it is matching exactly ...What could be the reason for this? here is the receiver code for UDP server

C++
char mesg[50];


n=recvfrom(sockfd,mesg,50,0,(struct sockaddr*)&cliaddr,&len);
fwrite(mesg,1,50,fp);



the values whatever is coming from client should be in the range of 3000 to -3000 but in some places it is going to 30000 to -30000. In wireshark i plotted that values it is coming exactly in 3000 to -3000 range. but if i plot the received buffer it is giving in the range of 3000 to -3000 but also more values are in the range of 30000 to -30000
Posted
Updated 4-Apr-13 23:08pm
v4
Comments
nv3 5-Apr-13 4:59am
   
Please show also the two results that you got from wireshark and your program. That would help making a good guess what the difference are and what they are coming from. (Use the "Improve question" button to append that information to your question.)

1 solution

Your fwrite call is wrong as it is assuming there are 50 characters in the received message. You should be using the value returned from the call to recvfrom thus:
C++
n = recvfrom(sockfd, mesg, 50, 0, (struct sockaddr*)&cliaddr, &len);
fwrite(mesg, 1, n, fp);
   
Comments
20038427 5-Apr-13 5:46am
   
Thanks Mr.Richard MacCuthan ...still the problem exists ...if i plot the output of the receive buffer it should be 3KHz here i am getting 3KHz but also some value going upto 30MHz ...
Richard MacCutchan 5-Apr-13 5:52am
   
Well , I am afraid it is impossible to guess what else is happening. You need to check all your code to ensure that you are only processing the actual number of characters received on each message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900