def getMsg(serialized): msg = chat_pb2.message() msg.ParseFromString(serialized) return msg
def newMsg(txt): msg = chat_pb2.message() msg.text = txt return msg
send_data(s, ("join", chat_details)) while True: socket_list = [sys.stdin, s] #Ignoring write and error sockets. read_sockets, _, _ = select.select(socket_list, [], []) for sock in read_sockets: #Incoming message from server if sock == s: data = recv_data(sock) if not data: sys.stdout.write("Disconnecting from server") exit() elif (data[0] == "error"): sys.stdout.write("Error: " + data[1].text) exit(); elif (data[0] == "message"): sys.stdout.write(data[1].text) #User pressed enter else: msg = chat_pb2.message() msg.text = sys.stdin.readline().decode('utf-8') send_data(s, ("message", msg))
send_data(s, ("join", chat_details)) while True: socket_list = [sys.stdin, s] #Ignoring write and error sockets. read_sockets, _, _ = select.select(socket_list, [], []) for sock in read_sockets: #Incoming message from server if sock == s: data = recv_data(sock) if not data: sys.stdout.write("Disconnecting from server") exit() elif (data[0] == "error"): sys.stdout.write("Error: " + data[1].text) exit() elif (data[0] == "message"): sys.stdout.write(data[1].text) #User pressed enter else: msg = chat_pb2.message() msg.text = sys.stdin.readline().decode('utf-8') send_data(s, ("message", msg))
def new_message(connections, sender_socket, nick, message): msg = chat_pb2.message() msg.text = nick + ": " + message for conn in connections: if conn is not sender_socket: send_data(conn, ("message", msg))