Group Chat on a Local Area Network
Localchat is a python library that helps setup server side and client side scripts of a Local Area Network Group Chat in no time. This library makes it very easy to share messages to all the devices connected on the same LAN.
Use the package manager pip to install localchat
pip install localchat
- Python 3 - Download here
- socket library (pre-installed with python package)
- threading library (pre-installed with python package)
import localchat localchat.help()
Calling help will list out all the details of the library.
localchat :: python library for quickly writing server and client side programs for a Chat Group on LAN Follow the below instructions to use this library Localchat library is pre-initialized with the following values of the GLOBAL variables PORT (port number) = 9999, FORMAT (encoding format) = 'utf-8' DISCONNECT_MSG (client disconnects on typing this message) = '!CONNECT' HEADER (buffer size to send the size of the message) = 64 1. initialize(port,format,header,disconnect_msg) - to change any of the pre-initialized global variables (should be same for server and client) 2. start_server() - binds the server with its (IP, PORT) and gets ready to accept multiple clients requests, receive messages and broadcast the messages to all the client available 3. start_client(server_ip) - connects the client with the server ipv4 address provided and gets ready to send and receive messages concurrently 4. send_message(client, message) - server can send the message to the client OR client can send message to the connected server 5. receive_msg(client) - server can receive message from the client OR client can receive message from the connected server 6. broadcast(message) - server broadcasts the message to all the available clients(ALL_CLIENTS) Will be adding new features soon ...
Sample Server Side Code
import localchat localchat.initialize(port = 9090, format = 'utf-8', disconnect_msg = 'disconnect') localchat.start_server()
Sample Client Side Code
import localchat localchat.initialize(port = 9090, format = 'utf-8', disconnect_msg = 'disconnect') server_ip = '22.214.171.124' # for example # ipv4 address of the server system (see below to find ipv4 address) localchat.start_client(server_ip)
How to find IPv4 address of any system
- run ipconfig command in command-promt and copy the IPv4 address under the
Wireless LAN adapter Wi-Fisection
The following arguments of the server and the client SHOULD BE SAME during
- The message encoding
header(variable to send the size of the message)
You are welcome to contribute via pull requests on GitHub
Stable Version - 1.1.0
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.