title: Eclipse base HTML5 Websocket and GlassFish
body: <p>Env for project: -
  Eclipse 3.6 (Eclipse-jee-helios) + HTML5 + JavaScript + Websocket + (grizzly) Glassfish 3.1.1</p>
  
  <p>I have deployed sample project and able to run using GF.</p>
  
  <p><strong>When i try to connect websocket it always call onClose.</strong></p>
  
  <p><strong>I tried: -</strong>
  asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true</p>
  
  <p>GF 3.1.1 supports web socket (Downloaded from <a href="http://glassfish.java.net/downloads/3.1.1-final.html" rel="nofollow">http://glassfish.java.net/downloads/3.1.1-final.html</a>)</p>
  
  <p>Browser like safari and Google Chrome supports websocket (i am using latest browser and checked with <a href="http://websocket.org/echo.html" rel="nofollow">http://websocket.org/echo.html</a> URL)</p>
  
  <h2>Java Script:-</h2>
  
  <pre><code>    var webSocket;
  
  $(document).ready(
  function() {
  
  **var URL = "ws://localhost:8080/SampleGF/WebSocketChatServlet";**
  
        //Tried using and lot of combination of URLS
        var URL = "ws://localhost:8080/";
        var URL = "ws://localhost:8080/SampleGF";
        var URL = "ws://localhost:8080/SampleGF/WebSocketChatServlet";
  
  webSocket = new WebSocket(URL);
  
  //alert("WebSockets are " + (window.WebSocket ? "" : "not ") + "supported"); 
  
  webSocket.onopen = function(event) {
      alert("OPEN")
  }
  webSocket.onmessage = function(event) {
      var $textarea = $('#messages');
      $textarea.val($textarea.val() + event.data + "\n");
      $textarea.animate({
      scrollTop : $textarea.height()
      }, 1000);
  }
  webSocket.onclose = function(event) {
      alert("CLOSE")
  }
  </code></pre>
  
  <p>});</p>
  
  <pre><code> function sendMessage() {
  var message = $('#username').val() + ":" + $('#message').val();
  webSocket.send(message);
  $('#message').val('');
  }
  </code></pre>
  
  <hr>
  
  <p>i have used ChatSocket.java, WebSocketChatServlet.java, ChatApplication.java as it is from below link: -</p>
  
  <p><a href="http://java.dzone.com/articles/creating-websocket-chat" rel="nofollow">http://java.dzone.com/articles/creating-websocket-chat</a></p>
  
  <p>i have added <strong>servlet-api.jar</strong> in my project library.</p>
  
  <p>Ref. Link: - <a href="http://tech.amikelive.com/node-269/eclipse-quick-tip-resolving-error-the-import-javaxservlet-cannot-be-resolved/" rel="nofollow">http://tech.amikelive.com/node-269/eclipse-quick-tip-resolving-error-the-import-javaxservlet-cannot-be-resolved/</a></p>
  
  <h2><strong>Web.xml: -</strong></h2>
  
  <p>I have added servlet and servlet-mapping as below:</p>
  
  <p>servlet</p>
  
  <pre><code>    description    WebSocketChatServlet  description 
      servlet-name   WebSocketChatServlet  servlet-name
      servlet-class  org.trivadis.websocket.servlet.WebSocketChatServlet  servlet-class
  </code></pre>
  
  <p>servlet</p>
  
  <p>servlet-mapping</p>
  
  <pre><code>servlet-name  WebSocketChatServlet    servlet-name
  url-pattern   /WebSocketChatServlet   url-pattern
  </code></pre>
  
  <p>servlet-mapping</p>
  
  <hr>
  
  <p>I am not sure what i am doing wrong....</p>
  
  <p>How can i check URL i am using is correct or not for websocket.</p>
  
  <p>GF location is <strong>D:\glassfish3\glassfish</strong> for my project.
  Project location <strong>D:\workspace\SampleGF</strong></p>
  
  <p><em><strong>Another reason: -</em></strong></p>
  
  <p>Even I tried WAR sample from below link: -</p>
  
  <p><a href="http://jarvana.com/jarvana/search?search_type=project&amp;project=grizzly-websockets-chat" rel="nofollow">http://jarvana.com/jarvana/search?search_type=project&amp;project=grizzly-websockets-chat</a></p>
  
  <p><strong>WAR File Name:</strong> -grizzly-websockets-chat-1.9.45.war </p>
  
  <p>I have imported above war file in Eclipse and deployed it on glassfish 3.1.1 server. After running it application always call onclose event.</p>
  
  <p>I have executed below command: -</p>
  
  <p>asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true</p>
  
  <p>and I am using browser like safari and Google Chrome supports websocket (i have tested it with below link <a href="http://websocket.org/echo.html" rel="nofollow">http://websocket.org/echo.html</a> URL)</p>
  
  <p>Can anyone help me out….. </p>