Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Websocket JSR 356 sample implementation on tomcat 7.0.52

 
ninad patil
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple websocket application which I have deployed on tomcat 7.0.52. I am using JSR 356 API javax.websocket-api-1.0-b08.jar.

My Java server side code is

import javax.websocket.server.ServerEndpoint;
import javax.websocket.*;

@ServerEndpoint("/hello")
public class HelloBean {


@OnMessage
public String sayHello(String name)
{
return name + "return";
}
}
Whenever i try to connect to websocket it throws me error that its close.

On Client end (javascript) : Code is as follows

var ws = new WebSocket("ws://localhost:8080/hello");

ws.onopen = function()
{
ws.send("Message to send");
};
ws.onmessage = function (evt)
{ // var received_msg = evt.data;
alert("Message is received...");
};
ws.onclose = function()
{
// websocket is closed.
alert("Connection is closed...");
};
I am not able to understand why it is showing connection is closed message.

Help on this will be much appreciated.

Thanks
NP
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the HelloBean class deployed in the ROOT web app? Only in that case would localhost:8080/hello be the correct URL. What happens if you go to http://localhost:8080/hello in your browser?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic