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

CodePudding user response:

The
reference at the 1st floor response:
because the server sends back to uppercase characters
 
Self. Request. Send (self. The data. The upper ())

You type A, and received A server to send back, you'll see two A


What about how to make it only output an A, I know the reason why the output of two A, is that there is no solution, output of only one,

CodePudding user response:

refer to the second floor wunaicj111 response:
Quote: reference at the 1st floor response:

Because the server sends back to uppercase characters
 
Self. Request. Send (self. The data. The upper ())

You type A, and received A server to send back, you'll see two A


What about how to make it only output an A, I know the reason why the output of two A, is that there is no solution, output of only one,

Was only one output, just and you play together
Like you
 
Self. Request. Send (" \ r \ nFrom server: {} \ r \ n ". The format (self. The data. The upper ()))

CodePudding user response:

The Telnet window, you can press the Ctrl +] enter the command mode, and then type the command sends a string:
 
Send hello world

Press enter to send, and then press enter to exit the command mode, you can see the server returns the string, not you
  • Related