Introduction

In this article I am demonstrating a chat application which can handle multiple users at the same time. It also supports file transfer.

It is entirely based on Java and consists of two parts: jMessenger (client application) and jServer (server application).

Features

Handles multiple users at the same time

Support for both public and private messages

User signup and login available

Support for file transfer

Using the code

Run the jar files jMessenger.jar and jServer.jar and do the following:

On jServer select "data.xml" as database file. This file contains usernames and passwords.

On jMessenger select "History.xml" as history file. This file is used to save chat history.

In many cases, if jMessenger cannot find the server then adjust firewall to give it network access.

Both applications are written in Netbeans and you can import source files in Netbeans to view and edit them.

Message structure

Each message in jMessenger has four fields:

type: This can be set to message, login, newuser, etc.

sender: The username of sender

content: Actual content of the message

Recipient: Username of recipient of the message

jServer

There are two main classes in jServer for handling connections and messages. On startup the SocketServer runs in
a separate thread. The job of SocketServer is to wait for connections and for each connection start a new thread ServerThread. Once the connection is
established, ServerThread will listen for any messages and hand it over to SocketServer to process. Also it will forward messages
from other users to the connected user.

Update

There was much confusion about two issues regarding the project. I would like to clarify that here.

1. Chat History is not complete. The project's main purpose was to demonstrate networking concepts and due to deadline limitation it was not completed.

2. Many people are confused why chat over different networks is not possible. To understand this, take the example of any web-server. For any browser to connect to a web-server, this server needs to have a global IP address so that it is visible on the Internet. Similarly jServer also is a application server and for chat over two different networks (say a campus LAN and DSL at your house), it also need to be run on a computer with a global IP address.

About this project

This is a class project which I wanted to share with others. Source code is licensed under The Code Project Open License (CPOL).
The purpose of this project was to demonstrate Java sockets, so the whole History feature is not
implemented as good as I would have liked. If this article proves to be any help, please let me know.

Hi, I am new with Java. I can't locate the data.xml and History.xml files in my computer. I find your application really helpful in understanding Socket's chat application and file transfer but i can't run it due to the mentioned problem...Please, help me out...Thanks

There u download the source code from the above link,just extract it any where..open the net beans project and select new-open project.at the time select both folder and give open.. so jserver ans jmessgr will be there in net beans... just run both.. start chat..dont forget to sign up,there will be browse button to browse the data.xml file in chat window....

I start learn java and start to writ my first program chat, but your chat is at more higher lever then my, and I would be very grateful if you live comments for some parts of code.
Sorry for my english)

thank you for this amazing project i really love it .. can you post a conceptual data model for the project please and if you can post a little more explanation on the project. it will be great .. thank you