Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C MFC VC++
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
 
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 4-Apr-13 23:51pm
Edited 5-Apr-13 0:08am
v4
Comments
nv3 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
n = recvfrom(sockfd, mesg, 50, 0, (struct sockaddr*)&cliaddr, &len);
fwrite(mesg, 1, n, fp);
  Permalink  
Comments
20038427 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 274
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 PIEBALDconsult 200
4 BillWoodruff 174
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100