Online Chatting App using Sockets in Python

Index

            1. Introduction
            2. General instructions 
            3. Commands Available
            4. Detailed Instructions
            5. Download 
            6. Code
            7. Credits
            8. GUI
            9. Demo Video
            10. Join My server :)  🔴

Introduction :-

                                   Hi there , this blog is about a " Online Chatting app " that I have created using Sockets in Python . It is a command line based app in which a group of people can chat together in a room . It works on local network as well as over internet. but there's a tricky part , you just cant expose your public IP . I do have mentioned the solution . Read this blog fully to find the help that you need .

General instructions to use :-

  • For using this app you just have to download the exe file and run it in your system . 
  • Best practice recommended is , create a folder in a location you desire . And move the exe file into that folder . 
  • Make sure that your PC is connected to the internet / connected to a router .
  • Sometimes it may ask you to disable the firewall .
  • You have two options you can either create a server or join a server  .
  • If you are hosting the server and you get disconnected unexpectedly , the chat room will end for all. 
  • Once you host a server , it'll ask for your Passcode  . 
  • Remember the Room Address generated is actually the encrypted version of the IP address in which you are running the server and the passcode is used as key in some manner. 
  • Then send the Room Address generated and the Passcode  and PORT  to the  people who you would like to invite .
  • For detailed instructions hold on .

Commands:

CLIENT COMANDS :

%ACTIVE-USERS  >>  Displays number of online users
%DISCONNECT      >> Closes the connection between the server

ADMIN COMMANDS :

$ACTIVE-USERS    >> Displays number of online users
$STOP-SERVER      >> To close the server 
$CLIENTS-BOOK   >> Displays the name of active clients
$KICK-OUT             >> To kick out a user who posts inappropriate message
$LOG-ON                 >> To start logging the chat history
$LOG-OFF               >> To stop logging the chat history

Detailed Instructions  :

Main Menu ***
  • This is the menu that appears when you run the app .
Choice 1 : Create a server ***
  • Local Host >> 
    • It means the server will run on your PC 
    • But only the computers connected to the same router that your PC has been connected , can connect to your server . It has less use but you can go through the demo of this app .
  • Dedicated Port details >> 
    • This option has to be selected when you are gonna expose your server to the internet so that anyone can connect to your server from all over the world :)
    • You would have to install additional software name Ngrok . 
    • This method has been separately explained . Go further below. 
When you select Local Host ***

  • Now share the details (Room address , Room passcode , PORT )with your friends .
  • Debug : 192.168.1.11 is nothing but your local IP address .
  • The server has been thus successfully created.
When a client gets connected   , this will be the interface for them ***



When a client gets connected this is the view of Admin ***

  • I hope you can explore the other things yourself . 
  • If you wanna watch a demo video . Find it at the end of this blog
*** The images shown here is taken while developing the code. Final app may differ slightly but the main things wont change 

Hosting the Server over the internet :-

  • Guide to Create a server using Dedicated PORT details.
  • Follow these steps to expose your server to the internet. 
  • For this purpose we have to use a TCP tunneling tool called  " Ngrok " 
  • You have other options like hosting the server in google cloud , port forwarding , but I haven't touched those.
  • This Tool can be setup quickly and is the easiest way to do .

  • Step 1 : Setting up Ngrok

  • Download Ngrok software     Ngrok Website
    • You'll be needed to create an account . Do as they say in the website
    • Verify the email.
    • Then run the Ngrok exe file.
    • You'll have to paste the authentication token from the website . 
    • Just copy paste that command it'll be done ;)


Authen Token




  • Best practice is to move the Ngrok exe file to the same folder in which you have stored the Chat App . 
  • Run the Ngrok App
Ngrok display 

  • Step 2 : TCP Tunneling 

  • To expose your local host as a public IP ;
  • Now run these commands ,
    • cls
    • ngrok tcp <port>    (say 5055)
  • After running the it'll display the following .
NGROK WINDOW : TCP TUNNELING

Creating a server by giving dedicated PORT details


  • Step 3 : Running the app

  •  So now when you select create a server in Chat app . you have to proceed with dedicated PORT details option. 
  • Before that you may use the Ngrok helper option
  • Give the following as inputs ,
    • IP = 127.0.0.1
    • PORT = <port> you gave in ngrok command ( say 5055 ) 
    • Pass code : <....>
  • But here's a important thing . Don't share these details .  Since we are linking our local host as public IP using ngrok app .You cant share this IP and PORT info.
  • So , open a Chat App in a new window  .

  • Step 4 : NGROK HELPER

  •  It'll ask for IP and passcode and port .
  • These details have to be got from NGROK FORWADING DETAIL in Line 5

  • Forwarding                    tcp:// 8.tcp.ngrok.io:18888 -> localhost:5055 
  • From this : (This is an example )
    • PORT = 18888
    • To get IP copy paste that "8.tcp.ngrok.io" in this website .
    • There we can get the IP address . as show in this fig .

    • Website to fetch IP address from Ngrok TCP Link 

    • Enter IP as 3.142.129.56
    • Now you'll get sharable details printed . 
    • Share those details with your friends . 
  • Now the server is running on your local host but it can be connected from all over the world :)

Download :


<< When you run the app the windows defender might say that the file may contain virus . 
 It says that because the app uses basic TCP code , which cud have false alarmed it.
 But I assure you that , I haven't inserted any malicious content  and the app is safe to use>>

<< If you wish you may scan it using Antivirus  before using>>

Download


<<  ! Download and use the exe file at your own risk  >>

Code :

<<The source code is available in my GitHub page . Use it as reference or you may also contribute>>

GitHub



Design Aspects  :

  • The admin can log the chat history by giving the command $LOG-ON. The messages that are exchanged in th server will be stored in  a log file with timestamps . 
  • There basic admin commands will be enough to host the server properly .
  • Since this app works using socket ,  in order get connected to server the client will be required with Servers IP address. 
  • So instead of sharing it openly. This app has a inbuilt Encryptor and Decryptor. 
  • Since it is in command line interface , your input might be sometimes splitted because of a new message .  

Credits :

Big credits to  💖 " Tech with Tim " 💖  This app has been built around the basic concepts taught by Tech with tim channel. I recommend you to watch the video .

GUI :-

  • I hope this app would be great when implemented in GUI format using Tkinter. 
  • I have planned to work on it . 
  • If you would like to contribute , feel free to do so in my GitHub repository 💪

Demo Video :-



Join My Server :-

   
            🔊 At random occasions I have decided to host a server and post the details here . If you wanna tryout the Chat App over internet without going through Ngrok stuff you can join here . For client side you don't need ngrok to connect to a server over internet  ;)
🟢 Online 
🔴 Offline
 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

📢 ROOM Announcement......
    Status          :  🔴
    Server IP     :  
    PORT          :  
    Passcode      : 1234

💻 Server will be open from [ 08:30 PM ] till [ 09:30 PM] on .........

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


>>>> Comment if you find any problem

HISTORY :
  • Room 1
    • Active from 10:30 AM to 11:30 AM on 26/02/2022
    • Server IP     :  UPTTPWUPSXS
    • Passcode      : 1234
    • PORT          :  17319
  •