def send_image(img_buf): global conn try: utils.send_data(conn, img_buf) utils.send_data(conn, bytes('enod!', 'ascii')) except: raise RuntimeError("ERROR sending image buffer")
def __init__(self, parent=None, admin=False): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) header_labels = ('Pseudo', 'Score') self.tblScores.setColumnCount(2) self.tblScores.setHorizontalHeaderLabels(header_labels) self.tblScores.horizontalHeader().setResizeMode(QHeaderView.Stretch) # Bind buttons self.btnLeave.clicked.connect(self.btnLeave_clicked) if not admin: self.btnEdit.hide() self.btnDelete.hide() # Get score list utils.send_data(utils.Global.sock_server, commands.CMD_GET_SCORES) scores = utils.recv_data(utils.Global.sock_server) self.tblScores.setRowCount(len(scores)) row = 0 for (login, score) in scores: self.tblScores.setItem(row, 0, QTableWidgetItem(login)) self.tblScores.setItem(row, 1, QTableWidgetItem(str(score))) row = row + 1
def send_msg(cmdstr, intdata): global conn msg = bytes("{}{:07}".format(cmdstr, intdata), "ascii") try: utils.send_data(conn, msg) except: raise RuntimeError("ERROR sending msg to client!!")
def send_code(code, lang): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(utils.MASTER_SOCK) utils.send_data(s, f"{lang}{code}", utils.Request.EXECUTE_JOB.value) job_id = utils.receive_data(s) return job_id
def btnJoinGame_clicked(self): row = 0 # Game selected ? try: row = self.tblGames.currentItem().row() except Exception as e: QMessageBox.about(self, 'Erreur', 'Veuillez sélectionner une partie !') return # Game full ? nb_current_players = int(self.tblGames.item(row, 1).text().split('/')[0]) nb_max_players = int(self.tblGames.item(row, 1).text().split('/')[1]) if nb_current_players == nb_max_players: QMessageBox.about(self, 'Erreur', 'La partie est pleine !') return # Password on game ? if self.tblGames.item(row, 5).text() == 'Oui': text, ok = QtGui.QInputDialog.getText(self, 'Mot de passe', 'Entrez le mot de passe de la partie :') if ok: if str(text) != self.passwords[row]: QMessageBox.about(self, 'Erreur', 'Mot de passe incorrect') return # Send data to add player in game utils.send_data(utils.Global.sock_server, commands.CMD_JOIN_GAME) utils.send_data(utils.Global.sock_server, [row, utils.Global.login]) in_game_window = InGameWindow(self, False) in_game_window.setWindowModality(QtCore.Qt.ApplicationModal) in_game_window.show()
def send_int_msg(self, cmdstr, intdata): self.msg = bytes("{}{:07}".format(cmdstr, intdata), "ascii") try: utils.send_data(self.sock, self.msg) except: #print("-- shit! --") return -1 return len(self.msg)
def handle_connection(conn, addr): global jobs, jobs_queue print('Connected by', addr) header = conn.recv(utils.HEADER_SIZE).decode() if header: token = header[:-1] flag = utils.Request(int(header[-1:])) if token != utils.TOKEN: utils.send(conn, "FATAL: Authentication Error") elif flag == utils.Request.GET_JOB_STATUS: job_id = utils.receive_data(conn) if job_id in jobs_output: utils.send(conn, utils.JobStatus.FINISHED.value) else: utils.send(conn, utils.JobStatus.WAITING.value) elif flag == utils.Request.GET_WORKER_STATUS: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(utils.WORKER_SOCK) utils.send_flag(s, flag.value) output = utils.receive_data(s) utils.send(conn, output) elif flag == utils.Request.EXECUTE_JOB: code = utils.receive_data(conn) job_id = str(uuid.uuid4()) thread = threading.Thread(target=forward_code, args=(job_id, code, flag)) jobs[job_id] = thread jobs_queue.append(job_id) utils.send(conn, job_id) elif flag == utils.Request.GET_OUTPUT: job_id = utils.receive_data(conn) if job_id in jobs_output: utils.send(conn, jobs_output.get(job_id)) elif job_id not in jobs: utils.send(conn, "FATAL: job id doesn't exist") else: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(utils.WORKER_SOCK) utils.send_data(s, job_id, flag.value) output = utils.receive_data(s) try: json.loads(output) jobs_output[job_id] = output except JSONDecodeError as e: pass utils.send(conn, output) conn.close() print('Disconnected from', addr)
def handle(self): url_list = [ self.start_url + "%s/" % (i) for i in range(1, self.max_page + 1) ] for url in url_list: html = crawl_url(url) send_data(self.primeval_url, html, self.platform) time.sleep(delay)
def _get_output(job_id): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(utils.MASTER_SOCK) utils.send_data(s, job_id, utils.Request(5).value) output = utils.receive_data(s) try: loads(output) except JSONDecodeError as e: output = {'message': output} return output return output
def spawn_peer_thread(soc, addr): #b = soc.send("welcome"+str(addr)) #print str(b)+"bytes send register_peer(soc, addr) while (1): rqst = utils.recieve_data(soc) print rqst if (len(rqst) != 0): resp = process_message(rqst) if resp == '': break utils.send_data(soc, resp)
def btnEditGame_clicked(self): utils.send_data(utils.Global.sock_server, commands.CMD_EDIT_GAME) self.game.name = self.edtGameName.text() self.game.nb_max_players = self.sbxNbMaxPlayers.text() self.game.type = self.cbxGameType.currentText() self.game.map = self.cbxGameMap.currentText() self.game.password = self.edtGamePassword.text() utils.send_data(utils.Global.sock_server, self.game) self.parent.refresh() self.close()
def btnInscription_clicked(self): username = self.edtUsername.text() password = self.edtPassword.text() confirmPassword = self.edtConfirmPassword.text() if password != confirmPassword: QMessageBox.about(self, 'Erreur', 'Les mots de passe sont différents !') else: utils.send_data(utils.Global.sock_server, commands.CMD_INSCRIPTION) utils.send_data(utils.Global.sock_server, [username, password]) response = utils.recv_data(utils.Global.sock_server) if response == commands.CMD_OK: QMessageBox.about(self, 'Inscription', 'Vous êtes maintenant inscrit !') self.close() else: QMessageBox.about(self, 'Erreur', 'Un erreur est survenue !')
def get_user_action(serv_soc, my_listening_port): while 1: cmd = raw_input('Cmd options: \n1. LOOKUP <RFC Id> <Title>\n'+\ '2. LIST\n3. GET <RFCC Id> <host> <port>\n'+'4. CLOSE\n') cmd_token = cmd.split() header_dic = {} header_dic['Host'] = socket.gethostname() header_dic['Port'] = str(my_listening_port) if cmd_token[0] == 'CLOSE': rqst = 'CLOSE ' + header_dic['Host'] + ' ' + str(my_listening_port) utils.send_data(serv_soc, rqst) exit() elif cmd_token[0] == 'LOOKUP': rfc_id = cmd_token[1] header_dic['Title'] = ' '.join(cmd_token[2:]) rqst = utils.create_rqst_message('LOOKUP', rfc_id, header_dic) soc = serv_soc elif cmd_token[0] == 'LIST': rqst = utils.create_rqst_message('LIST', 'ALL', {}) soc = serv_soc elif cmd_token[0] == 'GET': rfc_id = cmd_token[1] host = cmd_token[2] port = cmd_token[3] del header_dic['Port'] header_dic['OS'] = platform.system() rqst = utils.create_rqst_message('GET', rfc_id, header_dic) peer_soc = connect_to_server(host, int(port)) soc = peer_soc else: print 'Bad Command...\n' continue utils.send_data(soc, rqst) resp = utils.recieve_data(soc) print_response(resp) if cmd_token[0] == 'GET': file_cont = ''.join(resp.split('\n')[6:]) f = open('./recieved/' + str(rfc_id) + '.txt', 'w') f.write(file_cont) f.close()
def register_with_server(soc, my_listening_port): rfc_list = os.listdir('./rfc') header_dic = {} header_dic['Host'] = socket.gethostname() header_dic['Port'] = str(my_listening_port) for rfc in rfc_list: full_path = os.path.join('./rfc', rfc) file = open(full_path, 'r') file_str = file.read() file_lines = file_str.split('\n') rfc_title = file_lines[4].strip() rfc_id = file_str[file_str.find('Request for Comments:') + len("Request for Comments:"):].split()[0].strip() header_dic['Title'] = rfc_title msg = utils.create_rqst_message('ADD', rfc_id, header_dic) utils.send_data(soc, msg) data = utils.recieve_data(soc) print data
def btnCreateGame_clicked(self): utils.send_data(utils.Global.sock_server, commands.CMD_CREATE_GAME) game = Game(utils.Global.login, self.edtGameName.text(), int(self.sbxNbMaxPlayers.text()), self.cbxGameType.currentText(), int(self.cbxGameMap.currentText()), self.edtGamePassword.text()) utils.send_data(utils.Global.sock_server, game) self.parent.refresh() in_game_window = InGameWindow(self.parent, True) in_game_window.setWindowModality(QtCore.Qt.ApplicationModal) in_game_window.show() self.close()
def __main(): """Main function.""" parser = ArgumentParser(description="Test asr server.") parser.add_argument("asr_port", type=int, help="asr server port.") args = parser.parse_args() socket = init_socket(asr_ip(args.asr_port)) for pcm_data in get_pcm_data_list(TEST_WAV): transcript = send_data(socket, pcm_data) logging.info(transcript)
def refresh(self): # Get current game utils.send_data(utils.Global.sock_server, commands.CMD_GET_GAME) utils.send_data(utils.Global.sock_server, utils.Global.login) game = utils.recv_data(utils.Global.sock_server) if game == None: QMessageBox.about( self, 'Erreur', "La partie n'existe plus ! Le créateur a dû déserter !") self.parent.refresh() self.close() return self.game = game self.lblGameName.setText(game.name) self.tblPlayers.clear() for player in game.players: self.tblPlayers.addItem(player)
def spawn_serve_peers(lis_soc, ): while 1: peer_soc, peer_addr = lis_soc.accept() #print "my peer conected to me ",peer_soc,peer_addr msg = utils.VERSION + ' ' + str(200) + ' ' + 'OK' + '\n\n' rqst = utils.recieve_data(peer_soc) msg += 'Date: ' + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' GMT\n' msg += 'OS: ' + platform.system() + '\n' if rqst.split()[0] != 'GET': resp = utils.create_resp_message(400, header) else: msg_tokens = rqst.split('\n') rfc_id = msg_tokens[0].split()[2].strip() filePath = './rfc/rfc' + rfc_id + '.txt' file = open(filePath, 'r') file_str = file.read() msg += 'Last-Modified: ' + time.ctime( os.path.getmtime(filePath)) + '\n' msg += 'Content-Length: ' + str(len(file_str)) + '\n' msg += 'Content-Type: ' + 'text/text' + '\n' utils.send_data(peer_soc, msg + file_str)
def __init__(self, parent=None, game=None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) self.parent = parent self.game = game # Disable creation button self.btnCreateGame.setEnabled(False) self.sbxNbMaxPlayers.setRange(1, 12) # Fill the game types combobox types = ['FFA'] self.cbxGameType.addItems(types) # Get maps and fill the map combobox utils.send_data(utils.Global.sock_server, commands.CMD_GET_MAPS) nb_of_maps = utils.recv_data(utils.Global.sock_server) maps = [] for i in range(nb_of_maps): maps.append(str(i + 1)) self.cbxGameMap.addItems(maps) # Bind events self.edtGameName.textChanged.connect(self.text_changed) self.btnCancel.clicked.connect(self.btnCancel_clicked) if game == None: self.btnCreateGame.clicked.connect(self.btnCreateGame_clicked) else: self.btnCreateGame.clicked.connect(self.btnEditGame_clicked) self.btnCreateGame.setText("Modifier") self.edtGameName.setText(self.game.name) self.sbxNbMaxPlayers.setValue(int(self.game.nb_max_players)) type_index = self.cbxGameType.findText(self.game.type, QtCore.Qt.MatchFixedString) self.cbxGameType.setCurrentIndex(type_index) map_index = self.cbxGameMap.findText(str(self.game.map), QtCore.Qt.MatchFixedString) self.cbxGameMap.setCurrentIndex(map_index) self.edtGamePassword.setText(self.game.password)
def gaze_data_callback(gaze_data): """ Callback for Tobii Pro SDK, doing all the work once data arrives """ # Left eye gaze_left_eye = gaze_data['left_gaze_point_on_display_area'] gaze_left = { 'x': gaze_left_eye[0], 'y': gaze_left_eye[1], 'valid': gaze_data['left_gaze_point_validity'] } pupil_left = { 'diam': gaze_data['left_pupil_diameter'], 'valid': gaze_data['left_pupil_validity'] } left = {'gaze': gaze_left, 'pupil': pupil_left} # Right eye gaze_right_eye = gaze_data['right_gaze_point_on_display_area'] gaze_right = { 'x': gaze_right_eye[0], 'y': gaze_right_eye[1], 'valid': gaze_data['right_gaze_point_validity'] } pupil_right = { 'diam': gaze_data['right_pupil_diameter'], 'valid': gaze_data['right_pupil_validity'] } right = {'gaze': gaze_right, 'pupil': pupil_right} # Both eyes gaze = {'gaze': {'ts': time.time(), 'left': left, 'right': right}} # Send send_data(gaze) # Calculate fixations and send if a fixation was detected calculate_and_send_fixation(gaze['gaze'])
def refresh(self): # Get games list utils.send_data(utils.Global.sock_server, commands.CMD_GET_GAMES) games = utils.recv_data(utils.Global.sock_server) self.tblGames.clear() header_labels = ('Nom', 'Nombre de joueurs', 'Type', 'Carte', 'En cours ?', 'Mot de passe ?') self.tblGames.setColumnCount(6) self.tblGames.setHorizontalHeaderLabels(header_labels) self.tblGames.horizontalHeader().setResizeMode(QHeaderView.Stretch) self.tblGames.setRowCount(len(games)) self.passwords.clear() row = 0 for game in games: self.tblGames.setItem(row, 0, QTableWidgetItem(game.name)) self.tblGames.setItem(row, 1, QTableWidgetItem(str(len(game.players)) + "/" + str(game.nb_max_players))) self.tblGames.setItem(row, 2, QTableWidgetItem(game.type)) self.tblGames.setItem(row, 3, QTableWidgetItem(str(game.map))) self.tblGames.setItem(row, 4, QTableWidgetItem('Oui' if game.is_running else 'Non')) self.tblGames.setItem(row, 5, QTableWidgetItem('Non' if game.password == '' else 'Oui')) self.passwords.append(game.password) row = row + 1
def __asr(pcm_data_list, index): """asr. Args: pcm_data_list: pcm_data_list. index: index of pcm data. Returns: if recognize stop, new index of pcm data and transcript. """ begin_time = time.time() while True: trx = send_data(SOCKET, pcm_data_list[index]) if index == len(pcm_data_list) - 1: index, stop = 0, 1 break index, stop = index + 1, 0 if time.time() - begin_time > 0.1: break return stop, index, trx
def btnConnection_clicked(self): username = self.edtUsername.text() password = self.edtPassword.text() utils.send_data(utils.Global.sock_server, commands.CMD_CONNECTION) utils.send_data(utils.Global.sock_server, [username, password]) response = utils.recv_data(utils.Global.sock_server) if response == commands.CMD_OK: utils.Global.login = username # Launch game socket utils.connect_to_server_game() utils.send_data(utils.Global.sock_game, commands.CMD_STOCK_SOCK_GAME) utils.send_data(utils.Global.sock_game, username) utils.Global.game_thread = GameThread() utils.Global.game_thread.start() display_games_window = DisplayGamesWindow(self) display_games_window.show() self.hide() else: QMessageBox.about(self, 'Erreur', 'Une erreur est survenue')
login_gen = utils.login_dictionary_gen( "C:/Users/Jessica/PycharmProjects/Password Hacker/Password Hacker/task/hacking/logins.txt" ) pw_gen = utils.pass_gen2() login = next(login_gen) pw_accumulator = '' letter = '' password = '******' while True: data = utils.json_data(login, password) utils.send_data(client, data) dict_msg = utils.json_response(utils.receive_data(client)) msg = dict_msg['result'] if msg == 'Wrong login!': login = next(login_gen) logging.info(f'Login - {login}') else: break while True: letter = next(pw_gen) password = pw_accumulator + letter data = utils.json_data(login, password) start = time.perf_counter()
def run(self): while True: try: command = utils.recv_data(utils.Global.sock_game) except Exception as e: break if command == None: break if command == commands.CMD_LAUNCH_GAME: id = utils.recv_data(utils.Global.sock_game) map = utils.recv_data(utils.Global.sock_game) colors = utils.recv_data(utils.Global.sock_game) players = utils.recv_data(utils.Global.sock_game) screen = pygame.display.set_mode((700, 480)) pygame.display.set_caption("Multitron") background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((10, 198, 198)) wallImage = pygame.image.load("images/wall.png").convert() DOWN = 1 RIGHT = 2 LEFT = 3 UP = 4 PLAYER_SIZE = 5 WALL_SIZE = 30 clock = pygame.time.Clock() playersGrid = [] for i in range(96): playersGrid.append([]) for j in range(96): playersGrid[i].append(0) playerImage = pygame.image.load("images/player.png").convert() x = random.randint(10, 85) * 5 y = random.randint(10, 85) * 5 tmpY = math.floor(y / WALL_SIZE) tmpX = math.floor(x / WALL_SIZE) while map[tmpY][tmpX] != 0: x = random.randint(10, 85) * 5 y = random.randint(10, 85) * 5 tmpY = math.floor(y / WALL_SIZE) tmpX = math.floor(x / WALL_SIZE) direction = DOWN #random.seed(1) pygame.font.init() myfont = pygame.font.Font(None, 50) myfontScore = pygame.font.Font(None, 40) fontPlayerss = pygame.font.Font(None, 25) lose = False win = False score = 0 idEnemy = -1 running = True wait = True pygame.mixer.init() son = pygame.mixer.Sound("sounds/music.wav") son.play() while running: clock.tick(utils.fps) tmpX = math.floor(x / PLAYER_SIZE) tmpY = math.floor(y / PLAYER_SIZE) if not lose and not win: playersGrid[tmpX][tmpY] = id if direction == DOWN: y += PLAYER_SIZE elif direction == RIGHT: x += PLAYER_SIZE elif direction == LEFT: x -= PLAYER_SIZE elif direction == UP: y -= PLAYER_SIZE # Check wall collision tmpY = math.floor(y / WALL_SIZE) tmpX = math.floor(x / WALL_SIZE) if map[tmpY][tmpX] == 1: lose = True score = score - 150 # Check tail collision tmpY = math.floor(y / PLAYER_SIZE) tmpX = math.floor(x / PLAYER_SIZE) if playersGrid[tmpX][tmpY] == id: lose = True score = score - 200 # Check players collision elif playersGrid[tmpX][tmpY] != 0: lose = True score = score - 100 idEnemy = playersGrid[tmpX][tmpY] for event in pygame.event.get(): if event.type == QUIT: pygame.quit() if event.type == KEYDOWN: if event.key == K_RIGHT and direction != LEFT: direction = RIGHT if event.key == K_LEFT and direction != RIGHT: direction = LEFT if event.key == K_UP and direction != DOWN: direction = UP if event.key == K_DOWN and direction != UP: direction = DOWN if not lose and not win: screen.blit(background, (0, 0)) # Draw wall for i in range(len(map)): for j in range(len(map[i])): if map[i][j] == 1: screen.blit( wallImage, (j * WALL_SIZE, i * WALL_SIZE)) screen.blit(playerImage, (x, y)) # Draw players for i in range(len(playersGrid)): for j in range(len(playersGrid[i])): if playersGrid[i][j] != 0: pygame.draw.rect( screen, colors[playersGrid[i][j] - 1], (i * PLAYER_SIZE, j * PLAYER_SIZE, PLAYER_SIZE, PLAYER_SIZE)) for i in range(len(players)): label = fontPlayerss.render(players[i], 1, colors[i]) screen.blit(label, (520, 20 + (i * 40))) if lose: wait = False label = myfont.render("Vous avez perdu !", 1, (255, 0, 0)) screen.blit(label, (100, 100)) labelScore = myfontScore.render( "Score : " + str(score), 2, (255, 255, 255)) screen.blit(labelScore, (115, 135)) pygame.display.flip() elif win: wait = False label = myfont.render("Vous avez gagne !", 1, (0, 255, 0)) screen.blit(label, (100, 100)) labelScore = myfontScore.render( "Score : " + str(score), 1, (255, 255, 255)) screen.blit(labelScore, (115, 135)) pygame.display.flip() pygame.display.flip() utils.send_data(utils.Global.sock_game, idEnemy) idEnemy = -1 utils.send_data(utils.Global.sock_game, lose) utils.send_data(utils.Global.sock_game, playersGrid) allKills = utils.recv_data(utils.Global.sock_game) for i in allKills: if i == id and not win and not lose: score = score + 100 allLost = utils.recv_data(utils.Global.sock_game) nbPlayer = len(allLost) nbLost = 0 for i in allLost: if i == True: nbLost = nbLost + 1 if nbLost == (nbPlayer - 1) and not lose and not win: win = True score = score + 300 playersGrid = utils.recv_data(utils.Global.sock_game) utils.send_data(utils.Global.sock_game, score) if wait: utils.send_data(utils.Global.sock_game, False) else: utils.send_data(utils.Global.sock_game, True) finish = utils.recv_data(utils.Global.sock_game) if finish: if win: label = myfont.render("Vous avez gagne !", 1, (0, 255, 0)) screen.blit(label, (100, 100)) labelScore = myfontScore.render( "Score : " + str(score), 1, (255, 255, 255)) screen.blit(labelScore, (115, 135)) pygame.display.flip() time.sleep(2) running = False son.stop() pygame.display.quit()
idx = 0 t0 = time.time() with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((host, port)) while keep_running: # Grab and encode the image img_buffer = get_buffer() if img_buffer is None: continue # Prepare the message with the number of bytes going to be sent msg = bytes("image{:07}".format(len(img_buffer)), "ascii") utils.send_data(sock, msg) # Send the buffer utils.send_data(sock, img_buffer) # Read the reply command utils.recv_data_into(sock, tmp_view[:5], 5) cmd = tmp_buf[:5].decode('ascii') if cmd != 'image': raise RuntimeError("Unexpected server reply") # Read the image buffer size utils.recv_data_into(sock, tmp_view, 7) img_size = int(tmp_buf.decode('ascii'))
# # Push data live to API using Python on a RaspberryPi # import serial from utils import parse_data, send_data ser = serial.Serial('/dev/ttyACM0') while True: message = ser.readline() data = parse_data(message) if data: send_data(data)
def forward_code(job_id, code, flag): global jobs_output with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(utils.WORKER_SOCK) utils.send_data(s, job_id + code, flag.value)
def main(): msg = consumer.get_msg() url = bytes.decode(msg.value) html = crawl_url(url) send_data(url, html)
def run(self): colors = [] logins = [] id = 1 for player in self.players: colors.append((id * random.randint(0, 255) % 255, id * random.randint(0, 255) % 255, id * random.randint(0, 255) % 255)) logins.append(player.login) id = id + 1 for player in self.players: utils.send_data(player.sock, colors) utils.send_data(player.sock, logins) running = True while running: players_grid = [] idKill = [] idLost = [] for player in self.players: idKill.append(utils.recv_data(player.sock)) idLost.append(utils.recv_data(player.sock)) player_grid = utils.recv_data(player.sock) players_grid.append(player_grid) send_grid = players_grid[0] for grid in players_grid: for i in range(96): for j in range(96): if grid[i][j] != 0 and send_grid[i][j] == 0: send_grid[i][j] = grid[i][j] win = [] scores = [] for player in self.players: utils.send_data(player.sock, idKill) utils.send_data(player.sock, idLost) utils.send_data(player.sock, send_grid) scores.append(utils.recv_data(player.sock)) win.append(utils.recv_data(player.sock)) tmp = False for w in win: if w: tmp = True else: tmp = False if tmp: for player in self.players: utils.send_data(player.sock, True) running = False else: for player in self.players: utils.send_data(player.sock, False) for i in range(len(self.players)): database.Database.update_scores(self.players[i].login, scores[i])
import socket from threading import Thread from utils import ( obtain_data, send_data, print_data, ) if __name__ == '__main__': with socket.socket() as s: s.connect(('127.0.0.1', 666)) t = Thread(target=print_data, args=(s, )) t.start() while True: data = input('') if data == '_!exit': break send_data(data, s)