Skip to content

amit-c-ai/Chat-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chat-Application

alt text

This is an implementation of server-client Chat-Application using socket programming and some concepts of multi-threading. Basic idea of creating a chat-room is that create a server script and a client script. Server will act as a mediator, all clients will send messages to server and then server will send messages to all clients connected to it.

At this point everything works fine but on localhost. We can't send messages to person whose ip-address is not in out network. Reason:

To connect to an ip-address, it should be a public ip for example google, amazon, etc. 
But our ip-address is local provided by our ISP(Internet Service Provider). So clients to
connect to the server you created, it should be hosted on public domain.

This problem is solved by using ngrok, it basically gives us a public ip and tunnels the traffic at this ip to the port number we mention. We host the server at our localhost and some port (you'll understand after the example) and ngrok will tunnel the clients at its public ip to our localhost and mentioned port. We just need to share public ip and port (given by ngrok) to our friends.

  • installation:

    • clone this repository
    • install python for linux from here
    • open terminal and write "sh install.sh" without quotes
    • download ngrok from here and follow the procedure as mentioned on the page
  • get public ip:

    • first complete the procedure mentioned here
    • go to ngrok directory and write "./ngrok tcp 1060" without quotes

After this you'll see screen like this

highlighted line in image is the public domain and port(seperated by ':') you got and it is directed to localhost port 1060. Now server should be hosted at localhost 1060 and client should connect at ngrok-domain and port.

  • hosting server:

    • open a new terminal in cloned directory
    • command: python3 server.py 0.0.0.0 1060
    • server will start listening, ex
  • join server as client:

    • open a new terminal in cloned directory
    • command: python3 client.py ngrok-domain port nickname
    • Example
  • features:

    • large number of peope can join the server
    • as it uses tcp to connect, it is guaranteed that no messages will be lost
    • emogi supported texts using some commands (type "emogi -help" without quotes)
    • supports some funny linux commands, use following commands in chat:
      • /train/
      • /cowsay?Hello/
      • cowsay -help
      • /xcowsay?hello/ (cowsay and xcowsay have same commands just use xcowsay in place of cowsay)
      • /cowthink?hello/ (cowsay and cowthink have same commands just use cowthink in place of cowsay)
      • /xeyes/
  • bugs:

    • if only one client is connected and sends message, then it will go in infinite loop and server is crashed
    • if we write message on out terminal and someone's message comes then is get printed on the line we were writing
  • to prevent 2nd bug:

    • open two terminal and redirect output of 1st terminal to 2nd
    • run client script on 1st terminal and write your messages there
    • see others messages on 2nd terminal
    • you can achieve this using tty command

About

terminal based chat application in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published