Developing Your Own Chat Box

Reading Time: 2 minutes

In this modern  world of internet , reaching to your loved one is just a click away.In the olden days what took least two days to convey  your message takes now just two sec.. So is there something  special about this electronic postmaster..?? Yeah  it’s speed  is almost close to light , it has its own organized codes and at last it saves paper thereby is eco friendly!!!!

You must be wondering there must be a web of codes  in chat application , but surprisingly it’s is not that complicated. With a just few line of codes you can dive in your own chat room.

To make you believe that let me take a example for you , I use a PYTHON language to make a simple chat room.

Python is similar  to  other languages that we use , but with some ups and down!! This is a sample code for your first chat server

*Import socket //  header file

*a=socket.socket(socket.AF_INET, // socket.SOCK_STREAM)

*a.bind(“0.0.0.0” ,8000) // bind the socket to all IP use  port 8000

*a.listen(2) //allow 2 user at a time

*(Client ,(ip ,port))=a.accept() // ready to chat and return ip and port no. of connected message

*client.send(“hi”)  // sending message

The above 6 line of code can make a simple chat server. AF_INET and SOCK_STREAM are the protocol which internet uses. Google some of these things to  have in depth knowledge. After “accept” command it will wait for the machine to connect. For connection – open your terminal window and type  netcat  “ip address of the machine” 8000. It will get connected!!!

 

If you have a doubt leave comment and next time let’s see you in your own chat room .. See you there 😛  

Leave a Reply

CEV - Handout
%d bloggers like this: