I started writing a primitive ssh-like program for practice's sake. I was starting to check if the commands would be delivered properly before implementing any further functionality, so i just wrote a server which receives messages from the client and prints them in it's own console window, but before it receives a message, it sends a prefix to the client, which the client prints so it's right before ( to the left of) the user input. For the prefix to be to the left of the input i tried to use print( ... , end='')
, but that seems to break the whole thing, and the prefix then does not print at all, as opposed to the solution where the prefix is printed the line before, where the program works perfectly fine besides that little problem.
TL;DR :
this (where s is the socket)
for n, line in enumerate(sys.stdin):
prefix = s.recv(16)
print(prefix.decode('utf-8'), end='')
s.send(line.encode('utf-8'))
code does not print the received prefix at all, only after closing the program with CTRL + D or CTRL + C as shown below:
czyngis@czyngis-mint:[directory censored]$ python3 cmd_client.py -t fc70:6872:4c6:10ae:71c::1 -p 9999
target: fc70:6872:4c6:10ae:71c::1 | port: 9999
connection established with: fc70:6872:4c6:10ae:71c::1 on port: 9999
first code sample //< user input
does not work :( //< user input
^C<#CMD:><#CMD:><#CMD:>Traceback (most recent call last):
File "cmd_client.py", line 26, in <module>
for n, line in enumerate(sys.stdin):
KeyboardInterrupt
and this ( where s is also the socket )
for n, line in enumerate(sys.stdin):
prefix = s.recv(16)
print(prefix.decode('utf-8'))
s.send(line.encode('utf-8'))
code does print the prefix, but in the previous line, as shown below:
czyngis@czyngis-mint:[directory censored]$ python3 cmd_client.py -t fc70:6872:4c6:10ae:71c::1 -p 9999
target: fc70:6872:4c6:10ae:71c::1 | port: 9999
connection established with: fc70:6872:4c6:10ae:71c::1 on port: 9999
<#CMD:>
second code sample
<#CMD:>
works, but not quite :(^CTraceback (most recent call last):
File "cmd_client.py", line 26, in <module>
for n, line in enumerate(sys.stdin):
KeyboardInterrupt
Thank You for any help in advance.