LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2010, 02:12 PM   #1
kcleveland
LQ Newbie
 
Registered: Jun 2010
Posts: 28

Rep: Reputation: 0
Question Not receiving all data at server end of UDP socket- suggestions please.


Hey All-

I've written a UDP server and UDP client for some testing here at work, and I am sending a couple of floats (as a string) from the client to the server, and everything shows up correctly at the server EXCEPT for the first 3 characters of the string- they become strange characters and I cannot explain why.

Here is the relevant server-side code (let me know if you need more):

Code:
...
char rxdgram[1024];

len_inet = sizeof adr_clnt;
   z = recvfrom(s,
   	rxdgram,
   	sizeof rxdgram,
   	0,
	(struct sockaddr *)&adr_clnt,
	&len_inet);
   if (z < 0)
	bail("recvfrom(2)");

printf("%s",rxdgram);
...
and the relevant client-side code:
Code:
char dgram[1024]="0.735844;0.245885;1.343227;0.234825";

z = sendto(s,
	    dgram,
	    strlen(dgram),
	    0,
	    (struct sockaddr *)&adr_srvr,
	    len_inet);
	if ( z < 0 )
	    bail("sendto(2)");

z = strlen(dgram);
	if ( z > 0 && dgram[-z] == '\n' )
	   dgram[z] = 0; /*removes newline*/
and the server printf outputs this:
Code:
�_Z35844;0.245885;1.343227;0.234825
I've tried several novice hacks with no success (changing the data type of the buffer, etc.)- anyone have any suggestions/examples to help me along?

Thanks in advance!
 
Old 06-15-2010, 11:55 PM   #2
kapsikum
Member
 
Registered: Mar 2005
Location: INDIA
Posts: 79

Rep: Reputation: 16
Can you paste the code which is compilable and runnable directly.
 
Old 06-16-2010, 02:13 AM   #3
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Have you had a look at what's going on on-the-wire? That way you'll know if it's a client- or server-side issue. Wireshark is a good tool for that (most major distros have it as a package, though IIRC you may have to install wireshark-gui or something to get a GUI).
 
Old 07-02-2010, 10:11 AM   #4
kcleveland
LQ Newbie
 
Registered: Jun 2010
Posts: 28

Original Poster
Rep: Reputation: 0
Thanks for your replies everyone-

I got a veteran C programmer at work to help me- turns out that the FFT I was doing on the server side (not posted) had one parameter that was, as they say, "out of bounds" (I forgot about a null terminate on one line).

This is what was causing the final string being sent to be a character or two off, thus resulting in our wierd little characters posted above.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Not receiving UDP data duttaa Linux - Networking 4 08-19-2009 01:51 AM
problem in receiving data in udp sockets ramya_ts Linux - Embedded & Single-board computer 1 01-07-2009 02:12 PM
Multithread udp socket client fails to sendto data dilin Programming 0 04-06-2007 09:07 AM
Unable to receive data in an udp socket stephenwalter Programming 8 11-24-2005 11:20 PM
Receiving all data from socket Ohmu Programming 6 03-08-2004 01:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration