Usockets: How to specify an external format when opening a socket

I am trying to connect to a dirt client, so I use usockets to connect through tcp. But after I write, I get a decoding error message. I have a reason to believe that the encoding should be ascii or least used: clrf as the end of the line pointer, since the lines I read have ^ M to the end of the line

(let* ((sock (socket-connect "angalon.net" 3011)) (stream (slot-value sock 'stream))) (format stream "guest~%") (force-output stream) (dotimes (i 40) (read-line stream)) stream) :UTF-8 stream decoding error on #<SB-SYS:FD-STREAM for "socket 192.168.1.39:65516, peer: 93.174.104.58:3011" {1004129903}>: the octet sequence #(255 251 1 80) cannot be decoded. [Condition of type SB-INT:STREAM-DECODING-ERROR] 

I can verify that the external stream format is valid: utf-8, but the question is, how do I specify the external stream format that the socket gives?

 (let* ((sock (socket-connect "angalon.net" 3011)) (stream (slot-value sock 'stream))) (stream-external-format stream)) ;; => :UTF-8 
+2
source share
1 answer

Just by looking at the source for Clozure CL, the external format is hardcoded to ccl:*default-external-format* , which is UTF-8 on my system. The SBCL backend does not specify an external format, but it probably creates a socket with the default SBCL, which again is UTF-8. I don’t think there is a portable way to change the external format without modifying usocket.

However, you can associate sb-impl::*default-external-format* with the text :latin-1 before calling socket-connect :

 (let* ((sb-impl::*default-external-format* :latin-1) (sock (socket-connect "angalon.net" 3011)) (stream (slot-value sock 'stream))) (stream-external-format stream)) ;; :LATIN-1 

Edit: Also see FLEXI-STREAMS . I have not tested it, but you can convert the stream to FLEXI-STREAM and specify the external format.

+2
source

All Articles