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 = ''
PORT = 5000
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'
while 1:
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()
source
share