• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Websocket JSR 356 sample implementation on tomcat 7.0.52

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic