Python server echo before pressing enter

I had a strange problem and I can’t understand what is the reason! In fact, I wrote a simple server in Python that echo files everything that is included in the client. To test it, I connected to the server via telnet, but as soon as I enter the character, it will become an echo! I do not know how to stop this! Actually I want to finish the word and after pressing the enter key, my server echoes. Here is my simple server:

import socket
import sys

HOST = ''   # Symbolic name meaning all available interfaces
PORT = 5000 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

try:
    s.bind((HOST, PORT))
except socket.error , msg:
    print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()

print 'Socket bind complete'

s.listen(10)
print 'Socket now listening'

#now keep talking with the client
while 1:
    #wait to accept a connection - blocking call
    conn, addr = s.accept()
    print 'Connected with ' + addr[0] + ':' + str(addr[1])

    while True:
        data = conn.recv(1024)
        reply = 'OK...' + data
        if not data: 
            break     
        conn.sendall(reply)

conn.close()
s.close()
+4
source share
1 answer

According to the man page, the telnetclient tries to enter linemode and will return to character mode if the remote server does not support it:

, telnet TELNET LINEMODE. , telnet : " ", " " , .

, , "" , , .

, :

0x255 0x253 0x34

, ( ctrl right bracket), telnet ( , telnet BSD - Windows ).

^]toggle localchars
+4

Source: https://habr.com/ru/post/1622386/


All Articles