Hi, MRAB <pyt...@mrabarnett.plus.com> writes:
> 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? Thanks and well-spotted everyone! The missing newline was indeed the problem. With ssock.write(b'ECHO 1\n') the Python codes behaves like the Perl code. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list