You are not logged in.
Hello everybody.
I am writing a program in c, and I'm sending the data from a client struct to the daemon over socket.
I serialize the data with
char[100] msgbuf;
sprintf(msgbuf, "%s|%s|%d|%d", message->body, message->id, message->dur, message->tstart);
for debug, I printed msgbuf, and it looked as I would expect:
test message|test id|10|1309036867
however, the log from the daemon shows this as the string received:
test messagew(w
EDIT: looks like garbage chars didn't print, but they start before the w and after the e
both daemon and client are on the same machine.
deserialization fails, but thats bc the string sscanf is operating on is garbage.
I googled, but could not find anything useful.
any assistance or pointers (pun intended) greatly appreciated!
--mjheagle
Last edited by mjheagle8 (2011-06-26 02:26:34)
Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub
Offline
A few things. First, note that BBCode uses [ ] , not < >
Okay, msgbuf is crated correctly, but you don't show the rest of the code up to where it is sent. It is probably being stepped on by something.
How are you sending it?
Likewise, you don't show how you are receiving it -- what daemon ??
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
lol, sorry about the tags.
here's the program:
http://pastebin.com/8S4UjMdp
thanks in advance for your help.
Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub
Offline
You're not sending what you say you are. Take a good close look at this code and you should figure it out.
bzero(msgbuf, IDLEN+BODYLEN);
sprintf(msgbuf, "%s|%s|%d|%d", message->body, message->id, message->dur, message->tstart);
printf("%s\n", msgbuf);
write(sockfd, message->body, strlen(message->body));
Offline
ok, i got it. thanks for your help. cant believe i made such foolish mistake.
Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub
Offline