Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Desktop-based Chat Application using JavaFX, XML, & Socket Programming

NotificationsYou must be signed in to change notification settings

sarangsurve/javafx-chat-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Desktop-based Chat Application using JavaFX, XML, & Socket Programming.

Technology Stack

java

Introduction

Here, 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

  1. Handles multiple users at the same time
  2. Support for both public and private messages
  3. User signup and login available
  4. Support for file transfer

Using the code

Run the jar filesjMessenger.jar andjServer.jar and do the following:

  1. On jServer select "data.xml" as database file. This file contains usernames and passwords.
  2. On jMessenger select "History.xml" as history file. This file is used to save chat history.
  3. 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 tomessage,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 injServer for handling connections and messages. On startup theSocketServer runs in a separate thread. The job ofSocketServer is to wait for connections and for each connection start a new threadServerThread. Once the connection is established,ServerThread will listen for any messages and hand it over toSocketServer to process. Also it will forward messages from other users to the connected user.

// In ServerThread read the incoming message and hand it to SocketServerMessagemsg = (Message)streamIn.readObject();server.handle(ID,msg);.......// In SocketServer process the messages based on their typepublicsynchronizedvoidhandle(intID,Messagemsg){if(msg.type.equals("login")){        ....    }elseid(msg.type.equals("message")){if(msg.recipient.equals("All")){Announce("message",msg.sender,msg.content); }else{// Find the thread of recipient and forward it to him        }    }.......

jMessenger

jMessenger first connects to the jServer, specified by its IP-address and port number. Arriving messages are then displayed on message board along with their senders.

When a user wants to send a file, first his request is sent via a message of typeupload_req. The recipient then does the following:

  1. The recipient side sends its reply in a message of typeupload_res
  2. If request is accepted then the recipient opens a new port
  3. For positive reply, recipient's IP address and port number is sent back
  4. The sender, on receiving positive reply connects to this socket and starts file upload

An advantage of this approach is that the clients can chat and transfer files at the same time. Unlike messages, files do not go through jServer.

// On recipient side, start a new thread for downloadDownloaddwn =newDownload(....);Threadt =newThread(dwn);t.start();send(newMessage("upload_res",ui.username,dwn.port,msg.sender));// Reply to sender with IP address and port number.........// On sender side, start a new thread for file upload// Connect to the port specified in replyUploadupl =newUpload(addr,port,ui.file,ui);Threadt =newThread(upl);t.start();

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 theInternet. 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

Desktop-based Chat Application using JavaFX, XML, & Socket Programming

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp