Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets tutorial goes on tangents, used unwind-protect instead of macros #506

Open
bpseudopod opened this issue Aug 12, 2023 · 1 comment

Comments

@bpseudopod
Copy link
Contributor

The sockets tutorial is kind of a mess to read. Both sections are weighed down with an extended tangent about the "mistakes" that the author encountered, which are confusing to read and can't be much more helpful than simply explaining how to use the library correctly.

Additionally, the code on display ignores the convenience macros that usocket offers, such as instead implementing equivalent functionality with unwind-protect, requiring that the reader think about conditions and control flow when they should be focusing on the socket API.

This section should be rewritten to be more clear and direct, and should prefer the with- macros defined by the usocket package to unwind-protect.

I'll probably give a shot at rewriting it soon.

@NicoSimoski
Copy link

NicoSimoski commented Sep 30, 2024

I also stumbled over the unwind-protect and considered a rewrite of the socket-tutorial. The with-macros don't seem to belong to the API though: https://usocket.common-lisp.dev/api-docs.shtml. Are they considered stable or is there a more recent documentation?
Here are the functions for TCP without unwind-protect:

(defun create-server (port)
  (usocket:with-socket-listener (socket "127.0.0.1" port)
    (let ((connection (usocket:socket-accept socket :element-type 'character)))
      (format (usocket:socket-stream connection) "Hello World!~%")
      (force-output (usocket:socket-stream connection)))))

(defun create-client (port)
  (usocket:with-client-socket (socket stream "127.0.0.1" port :element-type 'character)
    (usocket:wait-for-input socket)
    (format t "Input is: ~a~%" (read-line stream))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants