Server---------------------
This simple implementation: The disadvantage of the client to start a process, the process is more than the machine to jump
#!/usr/bin/env python
# Encoding:utf-8
# DATE:2018/6/17
From socket Import *
From multiprocessing import Process
# Responsible for communication
DEF talk (conn):
While True:
Try
data = CONN.RECV (1024)
If not data:break
Conn.send (Data.upper ())
Except Connectionreseterror:
Break
Conn.close ()
# Build Links
def server (IP, port):
Server = socket (af_inet, SOCK_STREAM)
Server.setsockopt (Sol_socket, SO_REUSEADDR, 1)
Server.bind ((IP, port))
Server.listen (5)
While True:
conn, addr = Server.accept ()
p = Process (Target=talk, args= (conn,))
P.start ()
Server.close ()
if __name__ = = ' __main__ ':
Server (' 127.0.0.1 ', 8080)
Client-------------------
#!/usr/bin/env python
# Encoding:utf-8
# DATE:2018/6/17
# clients can start multiple processes and start one is a process
From socket Import *
Client = socket (Af_inet, SOCK_STREAM)
Client.connect (' 127.0.0.1 ', 8080)
While True:
msg = input (' >>>: '). Strip ()
If not msg:continue
Client.send (Msg.encode (' Utf-8 '))
data = CLIENT.RECV (1024)
Print (Data.decode (' Utf-8 '))
Multi-process concurrency simple socket