srvr.Initialize("srvr")
srvr.Port = 8888
srvr.AddWebSocket("/ws", "OnlineSocket")
srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")
srvr.AddFilter("/login_example/members/*", "MembersFilter", False)
Dim err As Map
err.Initialize
err.Put(404, "/404.html") 'page not found
err.Put(500, "/500.html") 'server error
srvr.SetCustomErrorPages(err)
srvr.Start
I then have a Class called 'OnlineSocket' and I am logging when a user connects etc.
B4X:
'WebSocket class
Sub Class_Globals
Private ws As WebSocket 'ignore
End Sub
Public Sub Initialize
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Log("Connected")
ws = WebSocket1
End Sub
Private Sub WebSocket_Disconnected
Log("Disconnected")
End Sub
I am also using the jNetwork library. This will listen for TCP & UDP messages coming from a Telnet device. (ServerSocket)
What I am trying to do is detect the incoming TCP/UDP message (which I have working) and only send that incoming message to some of the logged in user as a WebSocket.
For Example:
User 1 (User)
User 2 (User)
User 3 (Admin)
User 4 (User)
I only want the incoming messages from the TCP/UDP connection to be sent as a WebSocket message to the Admin (user 3) and user 1, 2 & 4 shouldn't see this WebSocket message.
Any ideas on how I can send a WebSocket message to only specific users from a different module (from the incoming TCP/UDP Module) ?
I apologize for reading hastily; maybe I did not understand the question and, moreover, I do not remember how filter works.
I think you should create a class (or at least a Type) for each user.
This class will contain a constant for the type of user, a reference to the relative websocket handler class [object] (you have a handler class which receives a websocket) and other stuff (user name, ...).
Then, a mapUsers of clsUser.