Python3 compiling C/S network program instance tutorial

Source: Internet
Author: User
This article mainly introduces how to compile a CS network program in python3, which has some reference value for those who learn Python network program design, for more information about how to compile a C/S network program in python3, see the following example. The specific method is as follows:

The example described in this article is a C/S applet compiled according to wingIDE prompts. The specific code is as follows:

The client myclient. py code is as follows:

#! /Bin/env python #-*-coding: gb18030-*-# import socket import timei = 1 while I <10: address = ("127.0.0.1", 3138) s = socket. socket (socket. AF_INET, socket. SOCK_STREAM) s. connect (address) buf = 'N': % d' % I s. send (buf. encode () # note that in python3.0, network transmission must be in the byte string format, such as s. send (B "abc") buff = s. recv (1024) if (len (buff): print (buff) s. close time. sleep (1) I + = 1

The myserver. py code on the server side is as follows:

#!/bin/env python#-*- coding:gb18030 -*-#import socketaddress=('127.0.0.1',3138)s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind(address)s.listen(10)while True:  cfd,address=s.accept()  buf=cfd.recv(1024)  print(buf,address)  cfd.send(buf)  cfd.close()

I hope the examples in this article can provide some reference for everyone's Python network program design.

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.