Geek Stuff > Tutorials > The Raspberry Pi Superuser > Setting up a chat server

Setting up a chat server


Hi, and welcome to the new Raspberry Pi Superuser! It's been three years since I updated the original set of tutorials, and I thought it was about time to make a few new ones. The Raspberry Pi lineup has changed in a lot of ways since then, but in a lot of ways it hasn't. The hardware has improved quite a bit from the original model B to the new RPi 2, but the basic premise of the machine and the system software have stayed, for the most part, the same.

But anyways, I digress. In this tutorial, I'll show you how to turn your Raspberry Pi into a basic chat server using the Cygnus/X trc protocol.

Ready? Let's get started.

So what's trc?

trc is an extremely simple chat protocol that I implemented in a few days in September 2015. I originally implemented it because the college that I'm at blocked IRC (boo!) and I wanted to have a replacement. It's functionally quite similar to IRC, but the protocol it uses is extremely simple and generates much less network traffic. (I wanted these traits for very... specific reasons.)

It's not extremely secure, so I wouldn't recommend using it for any extremely confidential discussions, but it certainly gets the job done for personal use.

Installing the Java 8 RE

The trc daemon (trcd) is written in Java and provided as a .jar file. In order to run it, you'll need to have the Java 8 runtime installed on your Pi. As the official Oracle JRE is no longer available as a Raspbian package, you'll need to download and install it manually. Run the following commands in a terminal: (LXTerminal if you're using Raspbian in desktop mode)

sudo chmod 777
sudo ./

These commands download a premade bash script from Cygnus/X and use it to install Java. If you feel uncomfortable giving root permissions to a random script from the internet (not a bad trait to have), click here to take a look at the script. If you want, you can run the commands manually as root.

Once you've completed one of the above methods, it's time to verify that Java installed correctly. To do this, execute the command:

java -version

The output of this command should be similar to:

java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) Client VM (build 25.71-b15, mixed mode)

and display that version 1.8.0_71 is installed.

Downloading and running trcd

Now that Java 8 has been installed and is running correctly, it's time to download and run the trc daemon. You can download it directly from Cygnus/X by running the following command as a regular user.

wget -P ~

Once the daemon is done downloading, you can execute it by running the command:

sudo java -jar ~/trcd.jar

If the command worked successfully, you should see output similar to:

pi@raspberrypi:~$ sudo java -jar ~/trcd.jar
[sudo] password for pi:
op> _

The "op> " prompt is the operator's prompt, which you can use later to perform basic administrative tasks on your server. But we're going to leave that where it is for now. Let's test to see if trcd is working correctly by running the trc client. To do this, open a new terminal window (or press Ctrl-Alt-2 if you're using ttys; you can press Ctrl-Alt-1 to return) and execute the following commands:

wget -P ~
cd ~
java -jar trc.jar localhost

If the server is up and running, you should see output similar to:

trc v0.05                                                                 10:53
hello from raspberrypi at raspberrypi/

there are currently 1 user(s) online
#nick auto set to user1 
[10:51:55] %user1 joined
> _

Customizing your server (optional)

Before you start getting people connected to your server, it's not a bad idea to do a bit of customization. trcd is limited in this regard, but it does allow you to show a custom message when people connect to your server. Assuming you've followed the instructions correctly up to this point, you can edit your message by running the following commands:

cd ~
sudo pkill -f 'java.*lntrcd'
nano .motd
sudo java -jar ~/trcd.jar

When you run nano .motd, you'll start up the nano text editor, which will allow you to enter a custom message. When you're done, Press Ctrl-X and make sure to specify yes.

If you don't know what to use for your custom message, try this one. It'll print out a colorful ASCII art Raspberry Pi logo on all ANSI-compatible terminal emulators.

   .~~.   .~~.
  '. \ ' ' / .'^[[31m
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) ^[(B^[[m    /Raspberry Pi/^[[31m
   '~ .~~~. ~'

Getting people connected to your server

Getting people connected to your server is rather simple and requires very little manual configuration. If they already have Java 8 installed, then it requires almost no time at all.

First run the java -version command on their computer using a terminal (cmd on Windows, Terminal on Mac OS) and verify that they have Java 8 installed. If not, then click here to go to the JDK 8 download site, choose the appropriate download, and set it up.

Once that's done, you can click here to download the trc .jar file. You'll execute it much in the same way that you did on your Pi, except instead of java -jar trc.jar localhost, you'll type java -jar trc.jar IP, where IP is the IP address of your Pi. If you don't know what your Pi's IP address is, click here to learn how to retrieve it.