Re: ServerSocket from within Tapestry
Hi Eugen, I like the look of the WebSocket library you shared: https://github.com/TooTallNate/Java-WebSocket. It is 100% Java, and includes example code for both server and client. Also it supports multi-threading 'out of the box'. So, if inside my Tapestry project's 'services' directory I create my own WebSocket server, extending the abstract server class included in the above library, it seems I can PUSH data out from the server simply by calling this service whenever a user makes a change using the Tapestry webapp. This way any connected desktop app clients always reflect current state. Have I understood correctly? Another small question... the demo server class in the above library includes a main method with the below lines of code to start up the server: WebSocketServer server = new SimpleServer(new InetSocketAddress(host, port)); server.run(); How do I start up this WebSocket server in the services directory of my Tapestry project? Thanks, Chris. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: ServerSocket from within Tapestry
Hi! I have to develop a chat on a Tapestry5 app and I have to include WebSockets. To do it i put the config below: I create a ChatServlet class outside Tapestry5 packages my.package. chat -> ChatServlet web. pages components services mixins ChatServlet.java : package mypackage.chat; @ServerEndpoint(value = "/chat") public class ChatServlet extends HttpServlet { @OnOpen public void onOpen(Session session) throws Exception { … @OnMessage public void onMessage(Session session, String message) throws Exception { … AppModule.java: public static void contributeIgnoredPathsFilter(final Configuration configuration) { configuration.add("/chat.*"); } web.xml chat-servlet mypackage.chat.ChatServlet 1 chat-servlet /chat And after to add this config, you can connect directly. With javascript is: new WebSocket("ws://"+ baseUrl +"/chat”); I hope the configuration for webapp helps you. Regards Carlos Montero Canabal > El 7/6/2018, a las 8:10, Christopher Dodunski > escribió: > > Thanks Eugen, and where did you place the server-side class decorated with > @ServerEndpoint("/ws")? Perhaps it doesn't matter whether it is placed in > 'pages' or 'services', as Tomcat finds it regardless. > > Is it necessary to invoke new threads (multi-threading) within each of the > methods decorated with @OnOpen, @OnClose, @OnMessage and @OnError, or does > Tomcat automatically handle cases of multiple, simultaneous client > connections? > > I found the below 'howto' on using Tomcat WebSockets, but the client side > code is implemented in HTML and JavaScript, not Java. It would be useful > to find some sample, client-side Java code for connecting and > communicating via a Tomcat WebSocket. > > https://examples.javacodegeeks.com/enterprise-java/tomcat/apache-tomcat-websocket-tutorial/ > > Regards, > > Chris. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org >
Re: ServerSocket from within Tapestry
Hi Christopher, In my case the annotation @ServerEndpoint decorates an Service implementation class. I don't invoke any threads in WS Methods, but, i think You can use the Tapestry's ParralelExecutor Service to optimize the processing of client requests (see https://tapestry.apache.org/parallel-execution.html) As WebSocket Client I use this library - https://github.com/TooTallNate/Java-WebSocket Regards Eugen 2018-06-07 8:10 GMT+02:00 Christopher Dodunski < chrisfromtapes...@christopher.net.nz>: > Thanks Eugen, and where did you place the server-side class decorated with > @ServerEndpoint("/ws")? Perhaps it doesn't matter whether it is placed in > 'pages' or 'services', as Tomcat finds it regardless. > > Is it necessary to invoke new threads (multi-threading) within each of the > methods decorated with @OnOpen, @OnClose, @OnMessage and @OnError, or does > Tomcat automatically handle cases of multiple, simultaneous client > connections? > > I found the below 'howto' on using Tomcat WebSockets, but the client side > code is implemented in HTML and JavaScript, not Java. It would be useful > to find some sample, client-side Java code for connecting and > communicating via a Tomcat WebSocket. > > https://examples.javacodegeeks.com/enterprise-java/tomcat/apache-tomcat- > websocket-tutorial/ > > Regards, > > Chris. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >