Git Product home page Git Product logo

chat-server's Introduction

The entire code is written in Python3.6. Please use this to thest both the server and the client.

For each part these are the two programs and their usage:

$ python3 user.py -h
usage: user.py [-h] [-s HOST] [-p PORT]

optional arguments:
  -h, --help  show this help message and exit
  -s HOST     specify remote server name or ip-address
  -p PORT     specify port number
  
$ python3 server.py -h
usage: server.py [-h] [-p PORT] [-c CLIENTS]

optional arguments:
  -h, --help  show this help message and exit
  -p PORT     specify port number
  -c CLIENTS  maximum number of clients

The sever uses multithreading with each thread given to a seperate user. The client uses two threads to handle receiving and sending seperated, with synchronisation taken care by a global lock.

Note-1:

I have made a few minor changes to the protocol messgaes, I had to make these changes to account for Python multi-threading, which does not include synchronization (like Java) and this had to be implemented using Locks:

For example: Each protocol message ends with a semi-colon, this is used to seperate the messages recieved by the client-buffer.

For this reason I would recommend my server and client against each other and not with some other Java code because this will break compatability.

Note-2:

 << is the input prompt
 >> is the output prompt

See example below. Sometimes a received message might be in the buffer and could take a few prompts before it is posted. For this reason press enter(return) key a few times at the input-prompt and the received message will be printed. This is essentially done to release the lock from input-prompt to the output prompt and go over the received-messages from the received-message-buffer.

Example of three clients and one server. I have used the default argumenst here. Ideally one much provide the arguments. Otherwise the host will default to localhost, and port to 58732.

    SERVER:
        $ python3 server.py 
        Social App running on HOSTNAME - v-76 

        vajj joined
        raj joined
        raj and vajj are now friends
        vajj posted: #status Jackson
        shant joined
        shant posted: #status Me

    CLIENT-1
        $ python3 user.py 
        Enter username: raj
        >>'raj' connected to server on ('v-76', 58732)
        << 
        <<
        >>received friend request from vajj: type '@friend vajj' to accept  OR 
        type '@deny vajj' to reject
        <<@friend vajj
        <<
        >>raj and vajj are now friends
        <<@add chelsea vajj
        <<
        <<
        <<
        >>vajj is now in group chelsea
        >>new status from 'vajj'': Jackson
        <<
        <<
        >>new user 'shant' has joined the app
        <<
        >>received friend request from shant: type '@friend shant' to accept  
        OR type '@deny shant' to reject
        <<

    CLIENT-2
        $ python3 user.py 
        Enter username: shant
        <<
        >>'shant' connected to server on ('v-76', 58732)
        <<@connect raj
        <<#status Me
        <<
        <<
        >>#statusPosted

    CLIENT-3

        $ python3 user.py 
        Enter username: vajj
        >>'vajj' connected to server on ('v-76', 58732)
        <<           
        >>new user 'raj' has joined the app
        <<@connect raj
        <<
        >>raj and vajj are now friends
        >>vajj is now in group chelsea
        <<#status Jackson
        <<
        >>#statusPosted

chat-server's People

Contributors

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