How to parse unsigned short integer value from net-receive
Posted: Tue Jan 29, 2013 3:43 pm
Hello
I know how to send unsigned short integer value with big-endian via TCP now.
But when trying to parse the unsigned short integer from bytes array returned by net-receive, I am stuck again.
Below is my codes, the server sends 3 bytes to client app written by newlisp.
The first byte is 0x01, the following two bytes are in big-endian, they represent one unsigned short integer here. I try to parse them using get-char twice. But it seems wrong.
I know how to send unsigned short integer value with big-endian via TCP now.
But when trying to parse the unsigned short integer from bytes array returned by net-receive, I am stuck again.
Below is my codes, the server sends 3 bytes to client app written by newlisp.
The first byte is 0x01, the following two bytes are in big-endian, they represent one unsigned short integer here. I try to parse them using get-char twice. But it seems wrong.
Code: Select all
(define (receive-challenge-string socket)
;; receive head
(unless (net-receive socket head 3) (quit-for-error))
(unless (= (get-char (address head)) 1) (println "SOH in challenge message is wrong"))
(println
(unpack ">u" (get-char (+ (address head) 1)) (get-char (+ (address head) 2)))
))