Python socket module: TCP,UDP client

Source: Internet
Author: User

__author__ = ' Administrator ' Import socket# TCP client Target_host = ' www.51cto.com ' Target_port = 80# af_inet is a standard IPV4 address or host name, Sock_stream represents the way TCP is the client = Socket.socket (socket.af_inet, socket. SOCK_STREAM) # Establish Connection Client.connect ((Target_host, Target_port)) # Send data client.send (' get/http/1.1\r\n host:51cto.com\r\n \ r \ n ') # receives the returned data, parameter is Buffersize.response = CLIENT.RECV (4096) print RESPONSE#UDP client Target_host2 = ' www.51cto.com ' target_ Port2 = 80# Creates a socket, Sock_dgram is the way of UDP. Client2 = Socket.socket (socket.af_inet, socket. SOCK_DGRAM) # No need to connect, send directly. Parameters: Send content, send target. Client2.sendto (' get/http/1.1\r\n host:51cto.com\r\n\r\n ', (Target_host2, Target_port2)) #获取返回数据, remote host information and port number data, Addr = Client2.recvfrom (4096) print data


This article is from the "Magicpwn" blog, make sure to keep this source http://magicpwn.blog.51cto.com/10497784/1688584

Python socket module: TCP,UDP client

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.