Quantcast
Channel: BinaryTides » Python
Viewing all articles
Browse latest Browse all 10

Python socket – chat server and client with code example

$
0
0
Socket based chat application
In our previous article on we learned about the basics of creating a socket server and client in python. In this post we are going to write a very simple chat application in python that is powered by sockets.
The chat application we are going to make will be more like a chat room, rather than a peer to peer chat. So this means that multiple users can connect to the chat server and send their messages. Every message is broadcasted to every connected chat user. The construction is as simple as the theory.
Code
The code consists of 2 python scripts. First is the server and the other is the chat client.
Chat server
The chat server does the following things
1. Accept multiple incoming connections for client.
2. Read incoming messages from each client and broadcast them to all other connected clients.
Here is the code of the chat server. It server opens up port 5000 to listen for incoming connections. The chat client must connect to this same port. You can change the port number if you want.
The server handles multiple chat clients with select based multiplexing. The select function monitors all the client sockets and the master socket for readable...

Read full post here
Python socket – chat server and client with code example


Viewing all articles
Browse latest Browse all 10

Trending Articles