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; package examples;
import javax.servlet.annotation.WebServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
@SuppressWarnings("serial") @WebServlet(name = "MyEcho WebSocket Servlet", urlPatterns = { "/echo" })
public class MyExampleServlet extends WebSocketServlet public class MyEchoServlet extends WebSocketServlet
{ {
@Override @Override
public void configure(WebSocketServletFactory factory) public void configure(WebSocketServletFactory factory)
{ {
// set a 10 second timeout // set a 10 second timeout
factory.getPolicy().setIdleTimeout(10000); 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; 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 * Example WebSocket, simple echo
*/ */
public class MyExampleSocket extends WebSocketAdapter @WebSocket
public class MyEchoSocket
{ {
@Override @OnWebSocketMessage
public void onWebSocketText(String message) public void onWebSocketText(Session session, String message)
{ {
// Echo message back, asynchronously // Echo message back, asynchronously
getSession().getRemote().sendStringByFuture(message); session.getRemote().sendStringByFuture(message);
} }
} }