Giter VIP home page Giter VIP logo

p2pchat's Introduction

Peer-to-peer Chat Style System

Done

  1. The server is running at Port: 6370(last four bit of my student ID) and allows up to 10 clients to connect.
  2. Each time a client connects to the server the event is announced to all connected clients.
    Message Format: { USER@ADD@[username - ip] }
  3. The Server can broadcast message to all clients which are connecting to itself.
    Message Format: { MSG@SERVER@ALL@[message] }
  4. The Server can kick any client which is connecting to itself.
    Message Format: { KICK }
  5. The client can broadcast message to all clients which are connecting to same server.
    Message Format: { MSG@[from user]@ALL@[message] }
  6. The client can send message to an other specific client which is connecting to same server.
    Message Format: { MSG@[from user]@[to user]@[message] }
  7. All the messages and commands above are listed in a log text area.
  8. All the clients are listed in the client end and server end.
  9. All above features are performed based on a GUI.

Design

class diagram

1. The MVC Architecture

1.1 Model

This layer is mainly responsible for data storage. In my P2P char app, I only need one model - User to store the username and ip address.

1.2 View

There are four views in my app - BaseView, ClientView, ServerView, and LoginFrame. LoginFrame is the entrance to login this app, while ClientView and ServerView organize the UI components for Client end and Server end, respectively. To reuse the code, the common parts of ServerView and ClientView are integrated in BaseView.

1.3 Controller

This layer provide with the core service of p2p. For example, as shown in above, the client end needs to connect/disconnect to a server, and send message.

2. Design Pattern - Singleton

According to actual needs, both the server and the client can only have one instance, so I use the singleton. For Example, The Server End:

public class ServerMain{
	//singleton pattern
	private static ServerMain instance = new ServerMain("Server End");
	private ServerView view;//the view
	
	/*
	* ctor
	*/
	private ServerMain(String str) {
		view = new ServerView(str);
	}
	
	public static ServerMain getInstance() {
		return instance;
	}
}

3. ConcurrentHashMap

A hash table supporting full concurrency of retrievals and high expected concurrency for updates. This class obeys the same functional specification as java.util.Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.

4. Flow Chart

flow chart

Bugs & Need to Improve

1. Can't disable the textfiled

In the LoginFrame, when user selects the client radio button, the username input textfiled still can be activated. It may be due to the addition of focus event listener for this textfiled. However, I do not have time to fix it.

2. Some parameters are fixed

The IP address, max number of connections and port number is constant. Maybe these parameters should be more flexible and set by users.

3. local area network

This chat software can only communicate each other in local area network. This software can further expand the range of user connections, making communication not only limited to local users

4. GUI

The GUI of client end and server end are simple, it can be rendered more beautiful and attractive.

My Github

More details are available at: P2P at Github 18372324

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.