Get FullRequestURI and parse it.
B4X:Log(ws.UpgradeRequest.FullRequestURI) 'http://localhost:51042/ws
Not my credit this time...Thanks Erel
Dim p As Int
If ws.Secure Then p = Main.srvr.PortSSL Else p = Main.srvr.Port
Not my credit this time...
Another solution:
B4X:Dim p As Int If ws.Secure Then p = Main.srvr.PortSSL Else p = Main.srvr.Port
Dim srvr(ServerArraySize) As Server
For ServerCount = 0 To ServerArraySize -1
srvr(ServerCount).Initialize("srvr")
srvr(ServerCount).AddWebSocket("/ws", "modETH484")
srvr(ServerCount).LogWaitingMessages = False
srvr(ServerCount).LogsRetainDays = 5
srvr(ServerCount).Port = ServerPortStart + ServerCount
Log ("Server at port " & srvr(ServerCount).Port)
' Log(srvr.CurrentThreadIndex)
srvr(ServerCount).LogWaitingMessages = False
srvr(ServerCount).Start
Next
<script>
//connect to the web socket when the page is ready.
$( document ).ready(function() {
b4j_connect("/ws");
// The confirm dialog. Ensure the selector and the b4j raise events naming are exactly matching in the B4J code
$( "#confirmdialog" ).dialog({
resizable: false,
height:180,
modal: true,
autoOpen: false,
buttons: {
"Ja": function()
{
b4j_raiseEvent("confirmdialog_event", {"result": "yes"});
$( this ).dialog( "close" );
},
"Nee": function()
{
b4j_raiseEvent("confirmdialog_event", {"result": "no"});
$( this ).dialog( "close" );
}
}
});
$( "#alertdialog" ).dialog({
resizable: false,
modal: true,
height:150,
width: 180,
autoOpen: false,
buttons: {
"Close": function()
{
b4j_raiseEvent("alertdialog_event", {"result": "close"});
$( this ).dialog( "close" );
}
}
});
});
</script>
Creating multiple servers is not the correct solution.
What are the clients? Android devices?
You can send any information you need between the client and the server after the websocket is connected.