B4J Question Can't connect to Jserver running on Linux

AKJammer

Active Member
Licensed User
Hey All,

I've been going through the forums trying to solve this one, but can't seem to get it. I created a Jserver as a webhook for SMS return messages from Nexmo (vonage). I tested it on my local PC running Windows with Postman emulating the SMS service. It receives the returned SMS and stores it into a SQLlite database. Another Handler is called from my B4J program and checks for any unprocessed messages. If there are any, it downloads the data and marks the sqlite record as processed. After 30 days the processed sqlite records are automatically removed.
I set up a VPS using IONOS.com.
Installed Java
SFTP'd my Jserver app "EVsms" to the VPS server /opt/evSMS
I'm using port 9955 for my application.
I opened the port in the firewall.
B4X:
iptables -I INPUT -p tcp -m tcp --dport 9955 -j ACCEPT

Then I started it:
B4X:
 nohup java -jar /opt/evSMS/EVsms.jar > nohup.out &
cat nohup.out
2020-06-12 19:14:40.829:INFO::main: Logging initialized @248ms to org.eclipse.jetty.util.log.StdErrLog
2020-06-12 19:14:41.259:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 11.0.7+10-post-Ubuntu-2ubuntu218.04
2020-06-12 19:14:41.322:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2020-06-12 19:14:41.322:INFO:oejs.session:main: No SessionScavenger set, using defaults
2020-06-12 19:14:41.327:INFO:oejs.session:main: node0 Scavenging every 600000ms
2020-06-12 19:14:41.336:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@365185bd{/,file:///opt/evSMS/www,AVAILABLE}
2020-06-12 19:14:41.338:INFO:oejs.AbstractNCSARequestLog:main: Opened /opt/evSMS/logs/b4j-2020_06_12.request.log
2020-06-12 19:14:41.362:INFO:oejs.AbstractConnector:main: Started ServerConnector@6c7f32ad{HTTP/1.1,[http/1.1]}{0.0.0.0:9955}
2020-06-12 19:14:41.362:INFO:oejs.Server:main: Started @789ms
Server started

Checking the port gives me:
B4X:
sudo nc -w5 -z -v 198.71.48.56 9955
Connection to 198.71.48.56 9955 port [tcp/*] succeeded!


sudo lsof -i -P -n | grep LISTEN
systemd-r   600 systemd-resolve   13u  IPv4  22612      0t0  TCP 127.0.0.53:53 (LISTEN)
java      26266            root   11u  IPv6 764759      0t0  TCP *:9955 (LISTEN)

So it looks like everything works, but when I go to test it from Postman I get <crickets> No connection

http://198.71.48.56:9955/test

Not even an error message saying bad data, just no connection.

What did I forget to do?

Thanks,
Jim
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User

i guess this is your url server, did you create the url handler with that name? webhook32623?

it looks something like this?
B4X:
    server.AddHandler("/webook32623","classWebhook",False)

then on the handler you need to write a resp. try a simple one. (you need to see what nexmo requieres you to write)

B4X:
resp.write("<p>test</p>")
if you dont add a resp.write or something else like resp.OutputStream.WriteBytes then it will wait for ever for a response until it times out.

last. it is a good practice to create a handler test:
B4X:
server.AddHandler("/test","classTest",False)

and in the handler return
B4X:
resp.write("<p>test</p>")

this way you can always test that your server is running
 
Upvote 0

AKJammer

Active Member
Licensed User
Hi Enrique,

Yes my handler is:
B4X:
Sub AppStart (Args() As String)
    srvr.Initialize("srvr")
    srvr.Port = 9955
    
    srvr.StaticFilesFolder = File.Combine(File.DirApp, "www")
    srvr.LogsFileFolder = File.Combine(File.DirApp, "logs")
    srvr.AddHandler("/webhook32623", "AcceptSMS", False)

Nexmo only wants a status of 2xx back, but I have a response
B4X:
    Dim msgcount As Int = Main.sql.ExecQuerySingleResult($"select count(*) from smsstore where processed = 0"$)
    
    resp.Status = 200
      
    resp.Write($"{"response":${msgcount}}"$)

I'll add a test handler, but I'm not getting anything from this one.

Jim
 
Upvote 0

AKJammer

Active Member
Licensed User
Arghh!! That was it. I added a /test handler as well. You should be able to ping it.

Thanks. I'll add it to the tab.

Jim
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
yes! working now!
1591995879665.png

Arghh!! That was it.
aah!! that extra layer is really nuisance, been there.

Thanks. I'll add it to the tab.
;)
 
Upvote 0
Top