Import sockettarget_host = "127.0.0.1" Target_port = 9999client = Socket.socket (socket.af_inet,socket. Sock_stream) Client.connect ((Target_host,target_port)) client.send ("get/http/1.1\r\nhost:baidu.com\r\n\r\n") Response = CLIENT.RECV (4096) print responseclient.close ()
This is the client port:
Import Socketimport threadingbind_ip = "0.0.0.0" Bind_port = 9999server = Socket.socket (socket.af_inet,socket. Sock_stream) Server.bind ((Bind_ip,bind_port)) Server.listen (5) print "[*] listen on%s:%d"% (Bind_ip,bind_port) def Handle_client (client_socket): request = CLIENT_SOCKET.RECV (1024x768) print "[*] Received%s"% request Client_socket. Send ("OK") client_socket.close () while true:client,addr = Server.accept () print "[*] Accepted connection from:%s :%d "% (addr[0],addr[1]) Client_handler = Threading. Thread (target=handle_client,args= (client,)) Client_handler.start ()
This is the service port:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7E/A8/wKioL1cGbd7zkyAwAAA9hw3BkLE144.png "title=" Qq20160407222253.png "alt=" Wkiol1cgbd7zkyawaaa9hw3bkle144.png "/>
This is the result of the operation.
What's up, I'm good, haha!
This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1761520
Simulating a TCP server and TCP connection with Python