Client可以透過房號登入,但仍無法多client
This commit is contained in:
parent
9b6edbbc49
commit
1c008e2029
19
main.py
19
main.py
@ -27,6 +27,7 @@ class Server:
|
|||||||
self.main(sock)
|
self.main(sock)
|
||||||
elif data == "CLIENT":
|
elif data == "CLIENT":
|
||||||
sock.send("OK.CLIENT".encode('utf-8'))
|
sock.send("OK.CLIENT".encode('utf-8'))
|
||||||
|
self.client(sock)
|
||||||
else:
|
else:
|
||||||
sock.send("FAIL".encode('utf-8'))
|
sock.send("FAIL".encode('utf-8'))
|
||||||
|
|
||||||
@ -55,6 +56,16 @@ class Server:
|
|||||||
sock.send("{} {}".format(roomNum,portNum).encode('utf-8'))
|
sock.send("{} {}".format(roomNum,portNum).encode('utf-8'))
|
||||||
# def getPort(self):
|
# def getPort(self):
|
||||||
# sock
|
# sock
|
||||||
|
def client(self,sock):
|
||||||
|
receiveMsg = sock.recv(MAX).decode('utf-8')
|
||||||
|
flag = False
|
||||||
|
for i in self.roomList:
|
||||||
|
if i['roomNum'] == receiveMsg:
|
||||||
|
sock.send(str(i['portNum']).encode('utf-8'))
|
||||||
|
flag = True
|
||||||
|
if not flag:
|
||||||
|
sock.send("FAIL".encode('utf-8'))
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
startFlag = False
|
startFlag = False
|
||||||
def __init__(self,ip,portNum):
|
def __init__(self,ip,portNum):
|
||||||
@ -97,7 +108,13 @@ class Client:
|
|||||||
room = Room(self.ip,int(connectData[1]))
|
room = Room(self.ip,int(connectData[1]))
|
||||||
room.connect()
|
room.connect()
|
||||||
elif receiveMsg=="OK.CLIENT":
|
elif receiveMsg=="OK.CLIENT":
|
||||||
print("CLIENT")
|
roomNum = input("Room Number> ")
|
||||||
|
sock.send(roomNum.encode('utf-8'))
|
||||||
|
receiveMsg = sock.recv(MAX).decode('utf-8')
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||||
|
sock.connect((self.ip,int(receiveMsg)))
|
||||||
|
print(sock.recv(MAX).decode('utf-8'))
|
||||||
else:
|
else:
|
||||||
print("ERROR TYPE")
|
print("ERROR TYPE")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user