Examples of ChatMessage


Examples of chat.Network.ChatMessage

                                        name = name.trim();
                                        if (name.length() == 0) return;
                                        // Store the name on the connection.
                                        connection.name = name;
                                        // Send a "connected" message to everyone except the new client.
                                        ChatMessage chatMessage = new ChatMessage();
                                        chatMessage.text = name + " connected.";
                                        server.sendToAllExceptTCP(connection.getID(), chatMessage);
                                        // Send everyone a new list of connection names.
                                        updateNames();
                                        return;
                                }

                                if (object instanceof ChatMessage) {
                                        // Ignore the object if a client tries to chat before registering a name.
                                        if (connection.name == null) return;
                                        ChatMessage chatMessage = (ChatMessage)object;
                                        // Ignore the object if the chat message is invalid.
                                        String message = chatMessage.text;
                                        if (message == null) return;
                                        message = message.trim();
                                        if (message.length() == 0) return;
                                        // Prepend the connection's name and send to everyone.
                                        chatMessage.text = connection.name + ": " + message;
                                        server.sendToAllTCP(chatMessage);
                                        return;
                                }
                        }

                        public void disconnected (Connection c) {
                                ChatConnection connection = (ChatConnection)c;
                                if (connection.name != null) {
                                        // Announce to everyone that someone (with a registered name) has left.
                                        ChatMessage chatMessage = new ChatMessage();
                                        chatMessage.text = connection.name + " disconnected.";
                                        server.sendToAllTCP(chatMessage);
                                        updateNames();
                                }
                        }
View Full Code Here

Examples of chat.Network.ChatMessage

                                        chatFrame.setNames(updateNames.names);
                                        return;
                                }

                                if (object instanceof ChatMessage) {
                                        ChatMessage chatMessage = (ChatMessage)object;
                                        chatFrame.addMessage(chatMessage.text);
                                        return;
                                }
                        }

                        public void disconnected (Connection connection) {
                                EventQueue.invokeLater(new Runnable() {
                                        public void run () {
                                                // Closing the frame calls the close listener which will stop the client's update thread.
                                                chatFrame.dispose();
                                        }
                                });
                        }
                });

                // Request the host from the user.
                String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
                        null, null, "localhost");
                if (input == null || input.trim().length() == 0) System.exit(1);
                final String host = input.trim();

                // Request the user's name.
                input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
                        null, "Test");
                if (input == null || input.trim().length() == 0) System.exit(1);
                name = input.trim();

                // All the ugly Swing stuff is hidden in ChatFrame so it doesn't clutter the KryoNet example code.
                chatFrame = new ChatFrame(host);
                // This listener is called when the send button is clicked.
                chatFrame.setSendListener(new Runnable() {
                        public void run () {
                                ChatMessage chatMessage = new ChatMessage();
                                chatMessage.text = chatFrame.getSendText();
                                client.sendTCP(chatMessage);
                        }
                });
                // This listener is called when the chat window is closed.
View Full Code Here

Examples of com.esotericsoftware.kryonet.examples.chat.Network.ChatMessage

          chatFrame.setNames(updateNames.names);
          return;
        }

        if (object instanceof ChatMessage) {
          ChatMessage chatMessage = (ChatMessage)object;
          chatFrame.addMessage(chatMessage.text);
          return;
        }
      }

      public void disconnected (Connection connection) {
        EventQueue.invokeLater(new Runnable() {
          public void run () {
            // Closing the frame calls the close listener which will stop the client's update thread.
            chatFrame.dispose();
          }
        });
      }
    });

    // Request the host from the user.
    String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
      null, null, "localhost");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String host = input.trim();

    // Request the user's name.
    input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
      null, "Test");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String name = input.trim();

    // All the ugly Swing stuff is hidden in ChatFrame so it doesn't clutter the KryoNet example code.
    chatFrame = new ChatFrame(host);
    // This listener is called when the send button is clicked.
    chatFrame.setSendListener(new Runnable() {
      public void run () {
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.text = chatFrame.getSendText();
        client.sendTCP(chatMessage);
      }
    });
    // This listener is called when the chat window is closed.
View Full Code Here

Examples of com.esotericsoftware.kryonet.examples.chat.Network.ChatMessage

          chatFrame.setNames(updateNames.names);
          return;
        }

        if (object instanceof ChatMessage) {
          ChatMessage chatMessage = (ChatMessage)object;
          chatFrame.addMessage(chatMessage.text);
          return;
        }
      }

      public void disconnected (Connection connection) {
        EventQueue.invokeLater(new Runnable() {
          public void run () {
            // Closing the frame calls the close listener which will stop the client's update thread.
            chatFrame.dispose();
          }
        });
      }
    });

    // Request the host from the user.
    String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
      null, null, "localhost");
    if (input == null || input.trim().length() == 0) System.exit(1);
    final String host = input.trim();

    // Request the user's name.
    input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
      null, "Test");
    if (input == null || input.trim().length() == 0) System.exit(1);
    name = input.trim();

    // All the ugly Swing stuff is hidden in ChatFrame so it doesn't clutter the KryoNet example code.
    chatFrame = new ChatFrame(host);
    // This listener is called when the send button is clicked.
    chatFrame.setSendListener(new Runnable() {
      public void run () {
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.text = chatFrame.getSendText();
        client.sendTCP(chatMessage);
      }
    });
    // This listener is called when the chat window is closed.
View Full Code Here

Examples of com.esotericsoftware.kryonet.examples.chat.Network.ChatMessage

          name = name.trim();
          if (name.length() == 0) return;
          // Store the name on the connection.
          connection.name = name;
          // Send a "connected" message to everyone except the new client.
          ChatMessage chatMessage = new ChatMessage();
          chatMessage.text = name + " connected.";
          server.sendToAllExceptTCP(connection.getID(), chatMessage);
          // Send everyone a new list of connection names.
          updateNames();
          return;
        }

        if (object instanceof ChatMessage) {
          // Ignore the object if a client tries to chat before registering a name.
          if (connection.name == null) return;
          ChatMessage chatMessage = (ChatMessage)object;
          // Ignore the object if the chat message is invalid.
          String message = chatMessage.text;
          if (message == null) return;
          message = message.trim();
          if (message.length() == 0) return;
          // Prepend the connection's name and send to everyone.
          chatMessage.text = connection.name + ": " + message;
          server.sendToAllTCP(chatMessage);
          return;
        }
      }

      public void disconnected (Connection c) {
        ChatConnection connection = (ChatConnection)c;
        if (connection.name != null) {
          // Announce to everyone that someone (with a registered name) has left.
          ChatMessage chatMessage = new ChatMessage();
          chatMessage.text = connection.name + " disconnected.";
          server.sendToAllTCP(chatMessage);
          updateNames();
        }
      }
View Full Code Here

Examples of com.jcloisterzone.wsio.message.ChatMessage

    @WsSubscribe
    public void handlePostChat(WebSocket ws, PostChatMessage msg) {
        if (!msg.getGameId().equals(game.getGameId())) throw new IllegalArgumentException("Invalid game id.");
        String clientId = getClientId(ws);
        ChatMessage reMsg = new ChatMessage(msg.getGameId(), clientId, msg.getText());
        broadcast(reMsg);
    }
View Full Code Here

Examples of com.pragprog.aebook.chat.client.ChatMessage

  public Key getKey() {
    return key;
  }
 
  public ChatMessage asChatMessage() {
      ChatMessage result = new ChatMessage(senderName, message, chat);
      result.setDate(date);
      return result;
  }
View Full Code Here

Examples of com.pragprog.aebook.persistchat.ChatMessage

            query.setFilter("chat == desiredRoom");
            query.declareParameters("String desiredRoom");
            query.setOrdering("date");
            List<ChatMessage> messages =  (List<ChatMessage>)query.execute(chat);
            // Get the most recent message.
            ChatMessage lastMessage = messages.get(messages.size() - 1);//(1)
            ChatMessageList result = new ChatMessageList(chat, lastMessage.getDate());
            result.addMessages(messages);
            return result;
        } finally {
            persister.close();
        }
View Full Code Here

Examples of com.pragprog.aebook.persistchat.ChatMessage

            query.declareParameters("String desiredRoom, Date earliest");//(6)
            query.setFilter("chat == desiredRoom && date > earliest"); //(7)
            query.setOrdering("date");
            List<ChatMessage> messages =  (List<ChatMessage>)query.execute(chat);
            // Get the most recent message.
            ChatMessage lastMessage = messages.get(messages.size() - 1);
            ChatMessageList result = new ChatMessageList(chat, lastMessage.getDate());
            result.addMessages(messages);
            return result;
        } finally {
            persister.close();
        }
View Full Code Here

Examples of com.pragprog.aebook.persistchat.ChatMessage

                }
            }

            /** Send a chat message to the server. */
            private void sendMessageToServer() { // (20)
                ChatMessage chatmsg = new ChatMessage(getUser(), messageBox
                        .getText(), getCurrentChat());
                messageBox.setText("");
                chatService.postMessage(chatmsg,
                        new AsyncCallback<List<ChatMessage>>() {
                            public void onFailure(Throwable caught) {
                                PersistChat.this.addNewMessage(new ChatMessage(
                                        "System", "Error sending message: "
                                                + caught.getMessage(),
                                        getCurrentChat()));
                            }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.