B4J Library Jakarta Websocket Server Library

Hey everyone, I was interested to Tyrus Server to deploy a Websocket server using Jakarta.
So I ends up wrapping this library hopefully you find it useful to your needs.

Library Functionality:
  • Initialize(EventName As String, contextpath As String, port As Int)
  • Start
  • Stop
Library Events:
  • Private Sub EventName_onOpen (session As SessionInfo)
  • Private Sub EventName_onMessage (session As SessionInfo, message As String)
  • Private Sub EventName_onClose (session As SessionInfo, statusCode As int, reason As String)
  • Private Sub EventName_onError (session As SessionInfo, errortext As String)
  • Private Sub EventName_onException (methodName As String, Exception As String)
SessionInfo :
  • Session_Id
  • isOpen
  • isSecure
  • MaxIdleTimeout
  • MaxTextMessageBufferSize
  • Protocol
  • ProtocolVersion
  • sendMessage(message As String)
  • close(statuscode as int, reason as string)
Closecodes_Utils :
Use it with SessionInfo.close method to specify the status code.

Example Attached with html test client so you can test the server.


Download Additional Jars From here

have a good day everyone and happy new year..
 

Attachments

  • Tryus_Jakarta_Websocket_Server_Library.zip
    12.7 KB · Views: 65
  • Example.zip
    3.9 KB · Views: 61
Last edited:

pixet

Member
Licensed User
Longtime User
I get an error on the client:

"Resource identified by path '/', does not exist."

the request is made like this http://localhost:6875/
if I do it with ws://localhost:6875/ it doesn't respond


How do I add a home page with events to manage
 

Addo

Well-Known Member
Licensed User
hey pixet here is a detailed example attached.

look at the part of initiating the websocket server

B4X:
websocketServer.Initialize("Adwebsocket", "pixet", serverPort)

'this can be
websocketServer.Initialize("Adwebsocket", "addo", serverPort)
websocketServer.Initialize("Adwebsocket", "b4x", serverPort)
websocketServer.Initialize("Adwebsocket", "anypath", serverPort)
'tyrus act diffrently than jetty you need to create an endpoint for each context path
'which means intializing a new ewebsocketserver for each path thats why you should rely on a single path
'and adjust the usage with something like json object to determine what to do with tha path by commands.
 

Attachments

  • Example.zip
    3.9 KB · Views: 54

Addo

Well-Known Member
Licensed User
about the http request to specify Webroot for the TyrusServerContainer which they use glassfish i have included an update in the firts post.
don't forget to create your webroot folder within your jar location.
you can expand this by programmatically creating those folders in run time inside b4j .
webroot folder can hold your context paths as well.

also I have changed the path of the Additional jars place all the jars inside a folder call it tyrus.
 
Last edited:

pixet

Member
Licensed User
Longtime User
Hi Addo,
I made a small donation for you.

Transaction code
6F081205KX174482H
 
Top