- Code: Select all
(defun serve (port)
(let ((sock (make-instance 'inet-socket :type :stream :protocol :tcp)))
(socket-bind sock (make-inet-address "127.0.0.1") port)
(socket-listen sock 100)
(let ((connection (socket-accept sock)))
It works, in that if I run (serve 5555) I can then use a telnet client to connect to localhost:5555 (which disconnects immediately). However, if afterwards I try to run the serve function again with the same port number, I get the error "<SB-BSD-SOCKETS:ADDRESS-IN-USE-ERROR>". If I change the port number, it will work once with that port, and then get the aforementioned error always after that.
I get the same problem trying to code something using usocket, which suggests a fundamental misunderstanding on my part. Is there a cleanup step I'm missing? (Like, "unbinding" the socket somehow?)