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)