"Learning notes" python network programming (i)

Source: Internet
Author: User

Server side:

Import Socket #导入socket模块s = Socket.socket (socket.af_inet,socket. SOCK_STREAM) host = "Port = 6074s.bind ((host,port)) #绑定主机和端口s. Listen (5) #监听传入连接, the maximum number of connections that the operating system can suspend CONN,ADDR=S.ACCE PT () #接受连接并返回 (CONN,ADDR) conn is used to receive and send data, addr is the connection client address print (' Connected by ', addr) #打印客户端地址while 1:data = CONN.R ECV (1024x768) #接收数据 if not data:break conn.sendall (data) #返回接收到的数据conn. Close ()

Client side:

Import sockets = Socket.socket (Socket.af_inet,socket.  SOCK_STREAM) host = "www.xiaoran.com" #服务器地址port = 6074 #服务器端口s. Connect ((host,port)) #连接服务器s. Sendall ("Hello World ") #将数据发送最大的连接套接字, but attempts to send all data before returning. Successful return none, Failure throws exception. data = S.RECV (1024x768) #接收套接字的数据, which is returned as a string. S.close () #关闭套接字print (' OK '), repr (data) #repr () converts the object to a string display, just for display (RELATED links


This article is from the "Autumn Breeze" blog, please be sure to keep this source http://aitiankong.blog.51cto.com/8923090/1564339

"Learning notes" python network programming (i)

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.