B4J Tutorial Tutorial - Run B4J webserver on VPS

Before you use this tutorial

  1. You need to know how to compile JRDC 2 jar file. Kindly Search the forum.
  2. You should have installed openjdk or oracle jdk in your server. For more information see the link http://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/ . You can also use other tutorials on internet. Search on google.

Step 1 : Log into your CentOs sever with any SSH client.( have admin rights to your account.) I use http://mobaxterm.mobatek.net/. You can use any other software you like.

Step 2 : You need to open the port number which your B4J webserver will use to communicate with your IOS or Andorid application. To know which port number is currently used. Go to configure.properties in your files folder and search for "ServerPort"
B4X:
#Java server port
ServerPort=51043
Type the below line in your CentOs terminal to open the port.
B4X:
sudo iptables -I INPUT -p tcp -m tcp --dport 51043 -j ACCEPT
To Check the open port. use
B4X:
iptables -L -n
You will get the following output
B4X:
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:51043

Step 3 : Upload the compiled Jar file into a folder of your choice. Here I have uploaded to /home/sk/b4ardc/

Step 4 : Run the Jar file using the below command
B4X:
nohup path_to_jdk -jar path_to_jarfile > nohup.out &

example -
nohup /opt/jdk1.8.0_91/bin/java -jar /home/sk/b4ardc/test.jar > nohup.out &
To know the path to Java, use
B4X:
whereis java

Step 5 : Confirm your B4J web server is running, use
B4X:
curl http://127.0.0.1:ServerPort/test

Example - 
curl http://127.0.0.1:51043/test

Output -
RemoteServer is running (2016-01-09 11:31:49)<br/>Connection successful.root@xxx [~]#

To access you B4J web sever from your application you can use the link
B4X:
http://yourwebsiteadress:51043/rdc
 
Top