Simple SSL client hangs
MRAB
python at mrabarnett.plus.com
Tue Jul 13 12:51:03 EDT 2021
On 2021-07-13 08:50, Loris Bennett wrote:
> Hi,
>
> 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?
>
The docs for Perl says that 'say' appends a newline.
On the other hand, 'ssock.write' doesn't append a newline.
Could that be the problem?
More information about the Python-list
mailing list