Jun-04-2019, 09:32 AM
I've tried to change my server socket's code to something like this...
import socket as skt import select as sel IP = "127.0.0.1" PORT = 9876 server_socket = skt.socket(skt.AF_INET, skt.SOCK_STREAM) server_socket.setsockopt(skt.SOL_SOCKET, skt.SO_REUSEADDR, 1) server_socket.bind((IP, PORT)) server_socket.listen() sockets_list = [server_socket] clients = {} print("Listening for connections on {}:{}".format(IP, PORT)) def receive_message(client_socket): try: message = client_socket.recv(1024) if not len(message): print("FALSE!") return False #return message.decode("utf-8") print(message.decode()) return message.decode() except: return False while True: read_sockets, _, exception_sockets = sel.select(sockets_list, {}, sockets_list) for notified_socket in read_sockets: #print(notified_socket) if notified_socket == server_socket: client_socket, client_address = server_socket.accept() message = receive_message(client_socket) print("Pre-Connected!") if message is False: continue sockets_list.append(client_socket) print("Connected!") else: message = receive_message(notified_socket) if message is False: print('Connection is closed...') sockets_list.remove(notified_socket) continue print(message + "123") for notified_socket in exception_sockets: sockets_list.remove(notified_socket)But when server receives the message, it's automatically receives one more empty message, which makes connection shut down. How can I fix that?