http client not working?

18 views
Skip to first unread message

Adam Feuer

unread,
Mar 12, 2023, 11:58:43 PM3/12/23
to chibi-...@googlegroups.com
Hi,

I'm working on an embedded systems project using Chibi Scheme. To start with I'm trying to get an http client and server working.

The http server seems to work ok. However, the http client hangs after connecting to it (or other websites)– reading from the socket input file object blocks without returning data.

The code for both programs is below. or you can see it on my branch of a fork of Chibi.

I've tested the server using Firefox and curl, and it works fine:

$ curl -D - "http://localhost:8000"
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8

<html><body><p>3</p></body></html>

The http server logs show a successful request:

2023-03-12 20:51:18 D net-server: accepting request: 2 ::ffff:127.0.0.1
2023-03-12 20:51:18 I (request: GET "/" "HTTP/1.1" ((host . "localhost:8000") (user-agent . "curl/7.79.1") (accept . "*/*")))
2023-03-12 20:51:18 D net-server: finished: 2

But when I use the new simple client, it just hangs with no output:

$ ./examples/simple-http-client.scm
Retrieving http://localhost:8000...

However, the server shows that the client connected:

2023-03-12 20:52:06 D net-server: accepting request: 4 ::ffff:127.0.0.1
2023-03-12 20:52:06 I (request: GET "/" "HTTP/1.0" ((host . "localhost") (user-agent . "chibi") (connection . "close")))
2023-03-12 20:52:06 D net-server: finished: 4

I must be doing something wrong– does anyone see anything incorrect or missing in the http client (code below)?

-adam
Seattle, WA, USA

. . . . . . . . .

#! /usr/bin/env chibi-scheme

; Simple HTTP server
; Returns a minimal HTML page with a single number incremented
; every request. Binds to localhost port 8000.

(import (chibi) (chibi net http-server) (chibi net servlet) (chibi sxml))
(let ((count 0))
   (run-http-server
    8000
    (lambda (cfg request next restart)
      (set! count (+ 1 count))
      (servlet-write request (sxml->xml `(html (body (p ,count))))))))

. . . . . . . . .

#! /usr/bin/env chibi-scheme

; Simple HTTP client
; Retrieves the contents of http://localhost:8000

(import (chibi) (chibi net) (chibi net http))

(let ((url "http://localhost:8000"))
    (display (string-append "Retrieving " url "..."))
    (newline)
    (display (http-get url))  
    (newline)
  )


Alex Shinn

unread,
Mar 14, 2023, 11:18:11 AM3/14/23
to chibi-...@googlegroups.com
Thanks, I can reproduce this.  It's hanging on sexp_poll_port.
This is a placeholder that seems broken.  If you (import (srfi 18))
it should work fine.  I'll see about fixing the non-threaded polling.

--
Alex

--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CAEDPjz6bvpMzVAwLO9KzqCO7oDK6WOv_5%2B9WG16BPfmEaQbzmA%40mail.gmail.com.

Alex Shinn

unread,
Mar 14, 2023, 9:19:21 PM3/14/23
to chibi-...@googlegroups.com
This should be fixed in HEAD.

Adam Feuer

unread,
Mar 14, 2023, 9:57:53 PM3/14/23
to chibi-...@googlegroups.com
Alex,

Thank you! I updated to HEAD and the example/client server work now.

-adam



--
Adam Feuer <ad...@adamfeuer.com>

Adam Feuer

unread,
Mar 14, 2023, 11:55:22 PM3/14/23
to chibi-...@googlegroups.com
I sent a PR with cleaned up http client and server examples in case you think they might be helpful:


-adam
--
Adam Feuer <ad...@adamfeuer.com>
Reply all
Reply to author
Forward
0 new messages