pack or udp ?

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

pack or udp ?

Post by newdep »

Hello Lutz,

Perhaps you can clarify my problem..

this is the string im sending

(net-send-udp "127.0.0.1" 5000 (pack "c c s7 c s4 c" (char 0) (char 1) text012" (char 0) "text" (char 0)))

But im receiving every time a different binary string on the listener side?

I you try to send the message above several times towards an (net-receive-udp 5000 128 ) and unpack the binarydata,
you will see that somting is wrong.. Although overhere its wrong..
perhpas its in the combined function call?

I dont see it... perhpas its the pack combination of srings and bytes? Or
perhpas its the \0x0 byte in the udp packet? or just a complete from function of mine ?

Regards, Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

(char 0) is not a number but a string! the format character 'c' is expecting a number between 0 -> 255 for a character (see manual), just like in the 'C' language. newLISP will take the address of the string and stuff the lower 8 bit into c, which is something different each time, when a new string gets allocated by (char 1) or (char 0) what you want to do is:


(pack "c c s7 c s4 c" 0 1 "text012" 0 "text" 0) => "\000\001text012\000text\000"

this will always give you the same results.

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Ieeeekkksss ... second time im doing this wrong ;-)
thanks!
-- (define? (Cornflakes))

Locked