Cleaning up examples for doc

This commit is contained in:
Joakim Erdfelt 2013-05-08 11:22:42 -07:00
parent c41a66bda8
commit 08161b5bf7
2 changed files with 15 additions and 9 deletions

View File

@ -18,18 +18,21 @@
package examples;
import javax.servlet.annotation.WebServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@SuppressWarnings("serial")
public class MyExampleServlet extends WebSocketServlet
@WebServlet(name = "MyEcho WebSocket Servlet", urlPatterns = { "/echo" })
public class MyEchoServlet extends WebSocketServlet
{
@Override
public void configure(WebSocketServletFactory factory)
{
// set a 10 second timeout
factory.getPolicy().setIdleTimeout(10000);
// register my socket
factory.register(MyExampleSocket.class);
// register MyEchoSocket as the WebSocket to create on Upgrade
factory.register(MyEchoSocket.class);
}
}

View File

@ -18,17 +18,20 @@
package examples;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
/**
* Example WebSocket, simple echo
*/
public class MyExampleSocket extends WebSocketAdapter
@WebSocket
public class MyEchoSocket
{
@Override
public void onWebSocketText(String message)
@OnWebSocketMessage
public void onWebSocketText(Session session, String message)
{
// Echo message back, asynchronously
getSession().getRemote().sendStringByFuture(message);
session.getRemote().sendStringByFuture(message);
}
}