B4J Question Multiple JServers only at specific SSL port / without binding at http port

Magma

Expert
Licensed User
Longtime User
Hi there...

Well i am using JServer but i want to have multiple https (only ssl) servers at my vps...

So i have already one running at port 5001 as ssl and i want one more...
but I today I ve seen that not only runs at 5001 (with ssl) but at 8080 (with no security)...

So if I create a 2nd jar - and put it at my Debian server / make my jks / set my ssl port fo example as 5002 - taking a msg:
./jrun
2025-09-30 19:29:27.058:INFO :eek:ejs.Server:main: jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 17.0.16+8-Debian-1deb12u1
main._appstart (java line: 64)
java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080

That because if I check the running PIDs with ss -tulpn - taking that already have a java server runs on:
tcp LISTEN 0 50 *:8080 *:* users("java",pid=2991635,fd=13))
tcp LISTEN 0 50 *:5001 *:* users("java",pid=2991635,fd=14))

* 5001 is my SSL setuped... the other must run somehow automatic from jserver - how to stop running from port 8080 or how to set it at different simple port / extra from ssl ?

I am using the following code:
B4X:
Sub AppStart (Args() As String)
   
   
    If File.Exists(File.Dirapp, "config.ini") Then
        settingsmap = File.ReadMap(File.Dirapp, "config.ini")
    Else
        Log("Error: No config.ini into directory.")
    End If

    If settingsmap.Get("SSL").As(String).Trim.ToLowerCase="false" Then
        srv.Port = settingsmap.Get("Port").As(Int)
    Else
        ConfigureSSL(settingsmap.Get("Port").As(Int)) '5002
    End If


    srv.Initialize("srvr")


    srv.AddHandler("/myactions", "InteractionsHandler",False)

    srv.Start
   
   
    InitializeBot
    StartMessageLoop
    srv.CreateThreadSafeMap
   
End Sub
 
Solution
Port 8080 is the default port used by jserver.
In your code, based on the settingsmap you read from the config.ini file, you set either the srv.Port (i.e. non-SSL) or the SSL port.
This means that when you set the SSL port, the non-SSL port is not explicitly set by your program and it defaults to 8080.
So, you just need to explicitly set the non-SSL port you want for your server in all cases (e.g. srv.Port=1234)

Philip Chatzigeorgiadis

Active Member
Licensed User
Longtime User
Port 8080 is the default port used by jserver.
In your code, based on the settingsmap you read from the config.ini file, you set either the srv.Port (i.e. non-SSL) or the SSL port.
This means that when you set the SSL port, the non-SSL port is not explicitly set by your program and it defaults to 8080.
So, you just need to explicitly set the non-SSL port you want for your server in all cases (e.g. srv.Port=1234)
 
Upvote 1
Solution

aeric

Expert
Licensed User
Longtime User
If I understand your problem, you are not setting a server port to 2nd server.

Server1
Port: not set default to 8080
SslPort: set to 5001

Server2
Port: not set default to 8080, conflict with Server1 already used port 8080
SslPort: set to 5002

You should explicitly set the port for each server.

Example:

Server1
Port: 8001
SslPort: 5001

Server2
Port: 8002
SslPort: 5002
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Let say your config.ini is as following:
config.ini:
Port=8002
SslPort=5002
UseSSL=True

Then your code should look like this:
B4X:
Sub AppStart (Args() As String)
    If File.Exists(File.DirApp, "config.ini") = False Then
        Log("Error: config.ini not found.")
        ExitApplication
    End If
    
    Dim settingsmap As Map = File.ReadMap(File.DirApp, "config.ini")
    Dim PORT As Int = settingsmap.GetDefault("Port", 8080) ' or 8002
    Dim SSLPORT As Int = settingsmap.GetDefault("SslPort", 0) ' or 5002
    Dim UseSSL As String = settingsmap.GetDefault("UseSSL", "False")
    
    srvr.Initialize("srvr")
    srvr.Port = PORT '8002
    If UseSSL.EqualsIgnoreCase("True") Then
        ConfigureSSL(SSLPORT) '5002
    End If

    srvr.AddHandler("/myactions", "InteractionsHandler", False)
    srvr.Start

    InitializeBot
    StartMessageLoop
End Sub
 
Upvote 1
Top