Simple SSL client hangs
Douglas Wells
nr201504 at gmail.com
Tue Jul 13 10:54:32 EDT 2021
In article <871r821wlg.fsf at hornfels.zedat.fu-berlin.de>,
Loris Bennett <loris.bennett at fu-berlin.de> wrote:
>In Perl I have the following
>
> use IO::Socket::SSL;
> my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
> PeerPort => 12345,
> );
> my $line = <$my_socket>;
> print("$line\n");
> say $my_socket 'ECHO 1';
> $line = <$my_socket>;
> print("$line\n");
>
>This runs as expected and I get
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
> 310 Hello Echo
>
>If I try the same with the following Python code:
>
> import socket
> import ssl
> HOST = "some.server.somewhere"
> PORT = 12345
> context = ssl.create_default_context()
> with socket.create_connection((HOST, PORT)) as sock:
> with context.wrap_socket(sock, server_hostname=HOST) as ssock:
> data = ssock.recv(1024)
> print(data.decode())
> ssock.write(b'ECHO 1')
> data = ssock.read(1024)
> print(data.decode())
>
>I get a timeout for the 'ECHO' command:
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
> 501 Timeout
>
>Does anyone have an idea what I might be doing wrong?
Loris,
You don't specify the type of your server, but it looks like a
"normal" SMTP or NNTP or whatever server. This type of server is line
oriented.
The Perl "say" operation adds a trailing line terminator. The Python
"ssl:write" does not. Try adding an appropriate line terminator to
your Python code. Most likely it needs to be CR-LF. Perhaps use
"ssock.write(b'ECHO 1\r\n')
- dmw
More information about the Python-list
mailing list