Home > other > The socket server why repeat output input characters
The socket server why repeat output input characters
Time:09-16
# coding=utf-8 The import SocketServer, sys
The class MyTCPHandler (SocketServer BaseRequestHandler) : Def handle (self) : Try: While True: self.data=https://bbs.csdn.net/topics/self.request.recv (1024) If not the self. Data: Print (" connection lost ") Break Self. Request. Send (self. The data. The upper ())
Pass Except the Exception as e: Print (self client_address, "disconnects") Finally: The self. The request. The close () Def setup (self) : Print (" before the handle, the connection is established, "and the self. Client_address) Def finish (self) : Print (" finish the run after handle ")
If __name__=="__main__" : The HOST, PORT="localhost", 9999 Server=SocketServer. TCPServer ((HOST, PORT), MyTCPHandler) Server. Serve_forever ()
After A SOCKET SERVER, TELNET, input A, AA, why two output, output how to make it only output A, thank you,
CodePudding user response:
Because the server sends back to uppercase characters
Self. Request. Send (self. The data. The upper ())
You type A, and received the server sends back A, you will see 2 A