Aldo Ziflaj bio photo

Aldo Ziflaj

Just another programming addict, with a sweet tooth for software development and cutting-edge technologies

Email Twitter Facebook Google+ LinkedIn Github

I started my 6th week of the challenge very late. In fact, I changed plans during the week, and decided to go with this application on Tuesday.

Why did I change the project middle-week?

A couple of times during the Software Engineering class, the professor has been saying “Don’t think Apache2 is Rocket Science! Even you can build your own server”. You don’t have to get that for granted, but keep in mind that the Internet Protocol (and also UDP and TCP) is built upon network sockets, so building a server basically means using sockets everywhere. That being said, he started showing how to use sockets with a simple PHP program, explaining what sockets are, how do they work, how PHP actually uses C in the background to achieve InterProcess Communication (IPC), etc. One of the things he mentioned was that of using multiple threads for serving more than one clients, and I actually took that as a challenge; to use Java Threads and [Server]Sockets in order to create a client-server application that allows clients communicate with each other.

What did I build

The application is very simple in concept and you’re probably familiar with the idea. It is an application that resembles an Internet Relay Chat, or IRC. IRCs were a way of group chatting over TCP that dates back in the late 80s. It is still used actually, just not that actively. You’ve probably heard of groups that use IRC:

One of the most known IRC networks known is Freenode, with more than 90 000 users in the world. Of course it’s not the only one, and some (so-called) modern group chat networks like Slack are built upon the same idea and model (with some added confidentiality).

What I did this week (actually, only in 2 days) was a simple application that resembles an IRC node, i.e. a server connected to multiple clients that allows different clients communicate with each other in a public chat. It should be noted that it is not a fully-featured IRC:

  • Usernames might conflict
  • You can’t ping another user
  • You have to manually create a different server process in order to create a different message thread
  • message threads are not stored or logged

Nevertheless, it can be a good Proof of Concept for different applications and examples. It uses Sockets and ServerSocket, different running threads for different clients, Swing API for the User Interface, and uses a single .properties file to store some necessary information to connect a client with the server.

How to set it up

Firstly, you’ll need to clone the repository of the project on GitHub:

There are two folders, Client and Server and also two shell scripts for compiling and running both the server and the client.

When I was in the first year of Computer Engineering, there was this professor teaching Computer Science 101 explaining the structures in C. He started his explanation saying: “Structures are… structures”. That being said, it should be obvious which one is the Client and which one is the Server.

The client comes with a file which you have to rename to and also put some useful information inside. Property files are containers of key-value pairs, and this file contains information about the server you want to connect (the hostname and the port) and also about you (the username). These values are then used to connect you to the server. Unfortunately, since most programmers are lazy, the server is not that customizable. The server runs on port 4444 (hard-coded) and you’ll have to change that if you want to bind the process to another port.

You can run the server and the client by executing:

# This is bash
# Sorry, Windows user :-(

# Run the server
$ chmod +x server
$ ./server -r

# Run the client
$ chmod +x client
$ ./client -r

Then you can use the UI client to chat all day long.

And that’s for the 6th week! If you want to make any changes, feel free to fork me on GitHub and fix anything you think should be fixed.