Simulating a TCP server and TCP connection with Python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.