Python_Socketserver的简单实现

import socket

if __name__ == __main__:

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #ipv4, TCP

sock.bind((0.0.0.0,5000)) #元组,相当于一个参数

sock.listen(10) #同时保持是十个人的连接

conn, addr = sock.accept()

while True:

data = conn.recv(1024) #最多1K的数据

print(data)

if data == bye:

break

else:

msg = raw_input(">>")

conn.send(msg)

sock.close()

print(Bye!!)