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!