Hi Dave

Well, to-binary won't do what you want.  REBOL is missing some pieces needed
for dealing with native binary integers.  Try this:

;change integer in range [-32768 32767] to 2-byte byte-reversed binary

to-2byte: func [x [integer!]][
 head reverse do join "#{" [(copy skip (to-string to-hex x) 4) "}"]
]

; examples

>> to-2byte 15
== #{0F00}

>> to-2byte 32767
== #{FF7F}

Hope this helps

Larry

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 05, 1999 1:03 PM
Subject: [REBOL] Newbie seeks help


> Hi, a couple of quick question on the problem I've been working on
> for a couple of days now....
>
> It quite simple really...how do you send an integer value as binary
> down a port ?
>
> I want to do something like this
>
> ; start of simplified source snippet
>
> server: open/binary tcp://127.0.0.1:9999
>
> MakeMail: func[MailPath]
> [
>
>
> CommandLength: make integer! length? MailPath
>
> insert server BinaryLength
> insert server MailPath
>
>
> ]
>
> MakeMail "/boot/home/mail/in/firstmsg"
> MakeMail "/boot/home/mail/in/secondmsg"
>
> close server
>
> ; end of source snippet
>
> and the server  (written in 'C++') receives the path length as a long
> or short or whatever,
> so if the length was 15 the buffer would hold 0x0F or 0x0F00 etc
> allowing for byte reversal,
> and knows how much data is needed for the path.
>
> the nearest I've got this to working is to use
>
> BinaryLength: make binary! (CommandLength)
>
> however probe BinaryLength just gives an empty binary #{} and the first
> thing
> received in the buffer is the start of the path.
>
> Any offers...?
>
> Dave
>
> BTW sorry about not sticking to the style guide but I've always found
> the
> bracket on the end of the line thing  difficult to read.

Reply via email to