0

System.out.println in java websockets is not working.

My aim is on user connects it should send first 'welcome' and then the chat have to be started.

This is tomcat7 websockets chat example:

 @OnOpen
    public void start(Session session,@PathParam("client-id") String clientId) {

    nickname = clientId;
    this.session = session;
    connections.add(this);
    System.out.println("welcome");
    String message = String.format("* %s %s", nickname, "has joined.");
    broadcast(message);


}

But it is not printing 'Welcome' to user.

Help me.

Manohar Gunturu
  • 125
  • 3
  • 16

1 Answers1

1

As already stated by @SLacks, you need to write to the socket, not to the system output stream.

Replace it with

session.getBasicRemote().sendText("welcome");

and it should do what you want. (You also will need to add handling for IOException).

Pavel Bucek
  • 5,304
  • 27
  • 44