我试图写一个服务器主要是从类的例子,因为我不知道是怎么回事。我的线路有问题-
(input,output,err)=select.select(socks,[],[])
我得到错误'无效参数',我不知道如何修复这个。我写的和课堂上一样。有人能帮我吗?谢谢你
#Server
import select
import socket
import math
import random
def within(guess,goal,n):
absValue = abs(guess - goal)
if absValue <= n:
return True
else:
return False
scoreCount = 0
guess = 0
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(("127.0.0.1",9000))
s.listen(5)
socks = []
while True:
(input,output,err)=select.select(socks,[],[])
for i in input:
if (i == s):
(c,a) = s.accept()
socks.append(c)
print ("Received connection from", a)
hello = c.recv(1024).decode()
print(hello)
c.send('Greetings\r\n'.encode())
goal = random.randrange(1,21)
while guess!= goal:
guess =c.recv(1024).decode()
guess = int(guess[7:len(guess)-2])
if guess == goal:
c.send('correct\r\n'.encode())
elif within(guess, goal, 2) == True:
c.send('close\r\n'.encode())
else:
c.send('far\r\n'.encode())
c.close()
目前没有回答
相关问题 更多 >
编程相关推荐