I was trying to deal with websockets using Jetty as the websocket server
I created a sample Stockticker Servlet example which generates price list every 5 seconds.
For that first I created a POM file
Code:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>main.java.org.demoServlet.app</groupId>
<artifactId>html5-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>html5-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<description>a project hosting an html5 webapp on jetty</description>
<build>
<finalName>html5-webapp</finalName>
<plugins>
<plugin>
<!-- This plugin is needed for the servlet example -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/html5-webapp</contextPath>
<descriptor>${basedir}/src/main/webapp/web.xml</descriptor>
</webAppConfig>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<source>1.6</source>
<target>1.6</target>
<minmemory>256m</minmemory>
<maxmemory>2048m</maxmemory>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jetty.version>8.1.2.v20120308</jetty.version>
</properties>
This is for jetty server . I used Eclipse as the IDE with run-jetty-run plug-in to run the jetty server.
Next was the servlet which extends WebSocketServlet it is html5servlet .
which uses doWebSocketConnect method for returning a websocket
doWebSocketConnect(HttpServletRequest req, String resp)
code for html5servlet is
Next is the StockTicketServlet class which implements OnFrame interface which is the extension of WebSocket and which overrides the websocket methods
code for StockTicketServlet is
Everything works fine ... I start the server .. It gets connected and displays Message Hello are you there WebSocket Server" that means onOpen event is called . But after that nothing happens . Ideally it should start posting prices every five seconds on the page. but nothing happens.
I am stuck for long and unable to debug the thing as well.
I urge to please help me out to fix this bug.