• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java multithreaded application with websockets

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I hope my question is ok for this forum.

I need to develop a java application that will run as a daemon inside a linux machine and will accept logins from remote browsers (Chrome, Firefox, ...) through WebSocket.

To do this, the application will have a thread called login_thread that waits for one remote client to send a login attempt through the websocket called login_websocket.
When the login attempt arrives, the login_thread creates a new thread called user_thread and move the login_websocket to this newly created thread (after that we will call it user_websocket), then creates a new websocket and waits on it for another client login attempt.
At the same time, the user_thread now sends and receives messages through the user_websocket till the remote client logs out.

I am searching for some advices on how to implement that architecture with Java. I've read articles and tutorials about Tyrus but it seems that using Tyrus I will not have the full control over the websockets that I need.

In short, I would like to do the same thing as described in this article:
http://tutorials.jenkov.com/java-multithreaded-servers/multithreaded-server.html

but using websockets and not simple sockets.

Is this possible? Is there a library that permits me to do this in a simple way?
Sorry if the question is dumb, but it is the first time I try to use websockets in Java and I feel a bit confused.

In JS, for example, the thing that I'm trying to do seems easily feasible.

Thank to each and everyone of you that will help!

- ipmpi
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I can see, websockets communicate over TCP so what you saw in the Jenkov tutorial should be sufficient. In other words, a "websocket" is a socket, it just isn't HTTP.
 
Marshal
Posts: 4829
605
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been wanting to use WebSockets for some of my applications, but haven't had the time to sit down and try something.  I was thinking that I would be able to stack Jersey, Tyrus, and Grizzly to build a Java SE server application supporting WebSockets, but I have not actually tried this yet.

In case you haven't already seen them, these pages provide some good information on WebSockets and Java:
  • Java API for WebSocket (Java EE)
  • How to build Java WebSocket Applications Using the JSR 356 API



  •  
    Ip Mark Ingram
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I checked especially Tyrus but it seems to add too much "magic": you have to have an annotated class and just hook up the events (new message, connect etc...) and I think I wanted some more flexibility. I hope I am understanding Tyrus's behavior and possibility correctly... It seems to me that it is very much "web application" oriented, and I have to implement a linux daemon and not a webapp :-)
    I am thinking about just implementing the WebSocket protocol over a simple "socket" in Java... I would have preferred to avoid that but it seems the only thing one can do to directly control multitheading and stuff...

    p.s. thank you for the suggestions, I've read the articles and I think I will try to follow them
     
    reply
      Bookmark Topic Watch Topic
    • New Topic