コード例 #1
0
def getMsg(serialized):
	msg = chat_pb2.message()
	msg.ParseFromString(serialized)
	return msg
コード例 #2
0
def newMsg(txt):
	msg = chat_pb2.message()
	msg.text = txt
	return msg
コード例 #3
0
ファイル: client.py プロジェクト: warna720/Simple-chat-server
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))

コード例 #4
0
ファイル: client.py プロジェクト: jtgalvez1/137Project

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))
コード例 #5
0
ファイル: server.py プロジェクト: warna720/Simple-chat-server
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)) 
コード例 #6
0
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))