python (select socket server)

# Author: Sooele
import select
import socket
import queue

server = socket.socket()
server.bind(('localhost',9000))
server.listen(1000)


server.setblocking(False) #不阻塞


inputs = [server,]
outputs = []

readable ,writeable,exceptional= select.select(inputs, outputs, inputs )
print(readable,writeable,exceptional)
select.select(inputs,outputs,inputs)

server.accept()
# Author: Sooele


import socket

HOST = 'localhost'  # The remote host
PORT = 9000  # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while True:
    msg = bytes(input(">>:"), encoding="utf8")
    s.sendall(msg)
    data = s.recv(1024)
    # print(data)

    print('Received', repr(data))
s.close()

发表评论