def __connect(self, macroboard):
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket.settimeout(DEFAULT_CLIENT_TIMEOUT)
with self.__socket:
self.__socket.connect((self.host, self.port))
self.__socket.sendall(self.__get_data(macroboard))
data = None
while not self.__cancelled and not data:
try:
# print('Recieve not cancelled')
data = self.__socket.recv(BYTES_LENGTH)
except socket.timeout:
continue
if self.__cancelled:
return
print('Received', repr(data), ' Size:', len(data))
try:
unpickled_data = pickle.loads(data)
except (pickle.UnpicklingError, EOFError):
raise BadResponseError('Response unpickling failed.')
if self.__is_not_valid(unpickled_data, macroboard):
raise BadResponseError('Response object is not valid.')
self.name, move = pickle.loads(data)
return move
评论列表
文章目录