1. 程式人生 > >多進程並發

多進程並發

accept pan style serve cep targe sta list soc

import socket
from multiprocessing import Process

def server(conn):
    msg = 連接成功.encode(utf-8)
    conn.send(msg)
    msg2 = conn.recv(1024).decode(utf-8)
    print(msg2)

    conn.close()
if __name__ == __main__:

    sk = socket.socket()
    sk.bind((‘‘,8080))
    sk.listen()
    while True:
        conn,addr 
= sk.accept() p = Process(target=server,args=(conn,)) p.start() sk.close()

多進程並發