File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSRs and the fly likes Websocket JSR 356 sample implementation on tomcat 7.0.52 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java JSRs » Other JSRs
Bookmark "Websocket JSR 356 sample implementation on tomcat 7.0.52 " Watch "Websocket JSR 356 sample implementation on tomcat 7.0.52 " New topic
Author

Websocket JSR 356 sample implementation on tomcat 7.0.52

ninad patil
Greenhorn

Joined: Mar 06, 2014
Posts: 1
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
Marshal

Joined: Mar 22, 2005
Posts: 42918
    
  68
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Websocket JSR 356 sample implementation on tomcat 7.0.52