MotivationWhen I wrote the MongoDB client library in R6RS portable manner, I have included socket procedures inside of the library. Now, I want to write Redis client, then I've noticed that it's very inconvenient that if there's no R6RS portable socket library. We have SRFI 106 for a socket library, however, it's not widely implemented especially on R6RS implementations. So I've decided to make it and it's here.
Portable R6RS socket library
ExampleThe library supports TCP and UDP client and server sockets. Most of the time, I only need TCP client, but it's nice to have in case it's needed. The very basic HTTP request call using this library would look like this:
(import (rnrs) (usocket)) (define client (make-tcp-client-usocket "google.com" "80")) (put-bytevector (client-usocket-output-port client) (string->utf8 "GET / HTTP/1.1\r\n\r\n")) (utf8->string (get-bytevector-n (client-usocket-input-port client) 1024)) ;; -> response from the server (usocket-shutdown! client *usocket:shutdown-read&write*) (usocket-close! client)For portability, we don't provide any socket specific operation other than
close. Everything else needs to be done via input or output port.
The library supports the following implementation:
- Sagittarius (0.9.4 or later)
- Chez Scheme (v9.5)
- Larceny (1.3)