Giter Site home page Giter Site logo

java_commandline_chatroom's Introduction

Java_CommandLine_Chatroom

To run the program:

# 1. complie all java codes
javac */*.java javac *.java

# 2. run the Server
# java Server [port] [block_duration] [time_out] 
java Server 2050 30 30

# 3. run the Client
# java Client [server_ip_address] [port] 
java Client localhost 2050

System Description

  • Server: After being started, the server would first create a server socket, which waits for a connection from a client.
    • When it receives a new connection, the server would create a new thread ServerConnection in charge of this new connection.
    • The thread would authenticate the client first. After authenticating, the client can send their commands and the thread would respond correspondingly.
  • Client: After being started, the client would start three threads:
    1. UserThread: in charge of dealing with the user input and send it to the server
    2. ServerThread: in charge of dealing with the client input and display it to the user
    3. P2PThread: in charge of dealing with the peer input or output and display it to the user

Application Layer Message Design

To keep messages between the server and clients as simple as possible, there are only few kinds of message formats:

  • From server to client:
    1. youare [username]: this message is used to set the username of the client after auth.
    2. p2p [username] [ip_address] [port]: this message is used to transfer the peer-to- peer information of another client.
    3. close: this message is used to close the client.
    4. text (Default): other messages would be displayed directly.
  • From client to server: the client would send user commands directly to the client.
  • From client to another client (peer-to-peer):
    1. thisis [username]: this message is used to inform the peer client the username.
    2. stopprivate [username]: this message is used to inform the peer client stop the connection with the user.
    3. text (Default): other messages would be displayed directly.

java_commandline_chatroom's People

Contributors

digitsisyph avatar

Watchers

James Cloos avatar  avatar

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.