Fork me on GitHub

Command-line demo

On the junixsocket releases page, you can find an archive of junixsocket's release jars along with a script to run some demos from the junixsocket-demo artifact.

junixsocket-dist comes either as a .tar.gz or .zip archive. Get either one of them.


Before we start running demos, let's make sure that junixsocket works on the current platform as expected.

junixsocket-dist provides a self-contained jar that performs this selftest:

java -jar junixsocket-selftest-X.Y.Z-jar-with-dependencies.jar

(Replace X.Y.Z with the corresponding junixsocket version)

The last line should read “Selftest PASSED”, and you're good to go.

If not, please file a bug report with the output of the selftest.

Running the demos

Simply run


from the junixsocket-dist-…-bin directory.

You will see a couple of examples on how to invoke the individual demos.

$ ./ 
Syntax: ./ [-m] [-j jar]+ [-- [java opts]*] <classname>

# Runs the demo server
# Runs the demo client

# Runs the demo RMI server
# Runs the demo RMI client

# Runs the demo server. Replace "(demo)" with the desired demo.
./ -- -Ddemo=(demo)
# Runs the demo client. Replace "(demo)" with the desired demo, and "(socket)" with the socket to connect to.
./ -- -Ddemo=(demo) -Dsocket=(socket)

# Runs the MySQL demo
./ -j (path-to-mysql-connector-jar) -- -DmysqlSocket=/tmp/mysql.sock

# Runs the PostgreSQL demo
./ -j (path-to-postgresql-jar) -- -DsocketPath=/tmp/.s.PGSQL.5432

# Runs the HTTP Server
./ -j (path-to-nanohttpd-jar) --

Other flags:
 -m Use the Java module-path instead of the classpath (Java 9 or higher)
 -j <jar> Add the given jar to the beginning of the classpath/modulepath
 -- Separate the run-demo flags from the Java JVM flags

For the server/client demos, you may want to run each part (the server and the client, respectively) in a separate terminal.

Demo server and demo client

The packages and contain a series of demos that can be launched using the script. Be sure to add the correct -Ddemo=... parameter before the classname (and right after the --).

Currently, the following demos exist:

  • Server

    • echo: Echoes all input, byte per byte.
    • null: Reads all input, byte per byte, not doing anything else with it.
    • zero: Writes null-bytes, and does not attempt to read anything.
    • chargen: A TCP-style character generator compliant with RFC 864.
    • send-fd: Opens a file and sends its file descriptor via ancillary message.
  • Client

    • read: Reads all input, echoing to stdout
    • read-write: Reads all input, echoing to stdout, and sends all data from stdin to the other side.
    • read-fd: Reads the content of any file descriptor sent via ancillary message. The in-band data is ignored.

NOTE: Some demos require additional parameters. These are shown upon invocation, and can be specified as Java system properties (-Dkey=value).