Python socket programming

Source: Internet
Author: User

Server

#! /Usr/bin/env python

Import socket

Import time

Host =''

Port = 99999

S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)

S. bind (host, port ))

S. listen (2)

While 1:

Conn, addr = s. accept ()

#---------------

Print 'got connection from: ', addr

While 1:

Data = conn. recv (4096)

Print 'get data', data

If not data: # determine whether a value is accepted

Time. sleep (1, 5)

Continue

Conn. sendall (data. upper ())

Print 'asdfasf', data

Conn. close ()

Client

#! /Usr/bin/env python

Import socket

Import time

H = '1970. 168.5.55'

P = 99999

S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)

S. connect (h, p ))

While 1:

S. send ('Hello word ')

Received_data = s. recv (1024)

Time. sleep (1.5)

Print 'safasfasf', received_data

S. close ()


This article is from the "Monitor hard disk usage" blog, please be sure to keep this source http://5471815.blog.51cto.com/5461815/1300203

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.