[racket] Issue reading bytes from TCP port

From: Gilbert Martinez (gil.martinez242 at gmail.com)
Date: Wed Sep 3 12:01:21 EDT 2014

I'm having issues reading the response from a TCP server.  Specifically,
any attempt to read the input port does not terminate.  I've used
port->bytes, read-byte, and read-line. In all cases the effect is the same.

I thought that if there were no bytes available on an input port that the
read attempt would just return <eof>.  Is this some kind of exclusivity
issue?  Can I not read from the port until the connection with the server
is closed or something?

My traffic monitor shows that the server is receiving the request and
responding (here is the exchange):

   Time Src. & Dst. Type Function Code Data  908.875    10.10.10.10:49967<- TCP
Req. 0x04 [0x000 - 0x027]     00 01 00 00 00 06 0B 04    00 3B 00 03
908.90510.10.10.10:49967-> TCP Resp. 0x04 [0x000 - 0x027]     00 01 00 00
00 09 0B 04    06 00 00 00 00 00 00


Here is the code I am using to query:

#lang racket


(define (hex-bytes->bytes hex-bytes-list)
  (define (hex-byte->dec-byte hex-byte)
    (string->number (string-append "#x" ((if (symbol? hex-byte)
                                             symbol->string
                                             number->string)
                                         hex-byte))))
  (apply bytes (for/list ((hex-byte (in-list hex-bytes-list)))
                 (hex-byte->dec-byte hex-byte))))

(define-values (c-in c-out) (tcp-connect "10.10.10.11" 502))

(write-bytes (hex-bytes->bytes '(00 01 00 00 00 06 0B 04 00 3B 00 03))
c-out)
(flush-output c-out)


I run the code above and execute the following in the interactions pane:


Welcome to DrRacket, version 6.1.0.5--2014-08-25(32ae3f8/a) [3m].
Language: racket [custom].
12
>(for ((byte (in-bytes (port->bytes c-in))))
  (printf "~x " byte))


The entry above above hangs on port->bytes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140903/84b5391e/attachment.html>

Posted on the users mailing list.