Python C/S model

Source: Internet
Author: User

server:

 #- *-coding: cp936-*-import socket, selects = socket. socket () host = socket. gethostname () # Get the host name Port = 5000 # specify the port number S. BIND (host, Port) # bind the port number and host name together S. listen (5) # Listen to a maximum of five clients connecting to inputs = [s] # Save the socket in the list while true: Rs, WS, ES = select. select (inputs, [], []) # input, output, error handling for R in RS: if R is S: client, ADDR = S. accept () # Return a new socket and address print "got connection from", ADDR inputs. append (client) # Add the returned new socket to the list else: Try: Data = R. recv (1024) # store the received data into the data disconnect = Not data into T socket. error: disconnect = true if disconnect: Print R. getpeername (), "Disconnect" # Return the inputs address to connect to the server. remove (r) else: print data  
 # client  
 #-*-coding: cp936-*-import socket, syssys. path. append ("C:/python25/Code") S = socket. socket () host = socket. gethostname () Port = 5000s. connect (host, Port) for line in open ("abb.txt"): Values = line. split ("^") for CSTR in values: signal_char = CSTR. strip ("~ ") S. send (signal_char) 

 
 
 
 

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.