-
1Getting started
Let's suppose to build a very simple BBS that asks your name and welcomes you. The basic operation is to extend PetsciiThread class (or AsciiThread for ASCII BBS) implementing doLoop() method, such as:
public class WelcomeBBS extends PetsciiThread { // NEVER forget default (empty) constructor public WelcomeBBS() { super(); // Recommended } @Override public void doLoop() throws Exception { // clear screen cls(); println("This is your brand-new BBS"); println(); print("Enter your name: "); // flush output flush(); // clear input buffer resetInput(); String name = readLine(); println(); println("Welcome, " + name + "!"); println("Press a key to exit"); flush(); readKey(); } }
-
2Building the server process
Once you have written your own BBS as an extension of PetsciiThread (or AsciiThread, as per previous documentation) class, simply build the fat jar with this command:
mvn clean packageThe build process will result in the file petscii-bbs.jar, it will be found in the target directory. So you can run it with:
java -jar target/petscii-bbs.jar
-
3Running the BBS Server
Running the server with no parameters, a help screen will be displayed:
usage: target/petscii-bbs.jar --bbs <bbsName:port> Run specific BBSes (mandatory - see list below) in the form <name1>:<port1> <name2>:<port2> ... -h,--help Displays help -s,--serviceport <arg> TCP port used by service process, 0 for no-service (default 0) -t,--timeout <arg> Socket timeout in millis (default 60 minutes) List of available BBS: * ... * WelcomeBBS
So we can rename the -jar file in bbs.jar, and the basic syntax for running our sample BBS is:
java -jar bbs.jar --bbs WelcomeBBS:6510
the port where the service will run is 6510 and the timeout is 3600000 milliseconds by default (1 hour). We can change the timeout parameter with -t switch:
java -jar bbs.jar --bbs WelcomeBBS:8088 -t 7200000
It's possible to run multiple BBSes, each one on a different port:
java -jar bbs.jar --bbs WelcomeBBS:6510 NewsBBS:8400 SportsBBS:9100 -t 7200000
(so the port will be 8088 with a timeout of 2 hours)
It's possibile to specify a "Service Port", which makes accessible (via web browser) the inspection of JVM running BBSes:
java -jar bbs.jar --bbs WelcomeBBS:6510 NewsBBS:8400 SportsBBS:9100 -s 8080
-
4Keep it running
This .jar is intended to be a server process: it has to run all time. So, it's a good thing to run it in background if you use a UNIX shell using nohup command with bash "&" operator:
nohup java -jar bbs.jar --bbs WelcomeBBS:6510 &
It's VERY important not to forget the final & symbol to keep it running. After launching that, you can logoff from your server.
-
5Stopping it
It's a plain process, so use plain ps and kill commands. If this jar is the only one running on your server, this command will do the work:
killall java
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.