a tiny terminal chat app that lives on your local network.
no account
no cloud
no database
no internet
just wifi and python.
lanchat lets multiple computers on the same local network chat with each other from the terminal.
one computer runs the server.
everyone else runs the client.
the client can automatically find the server using a udp broadcast. once it finds the server, the actual chat uses tcp.
so basically:
computer 1
|
| python server.py
|
+------ same wifi ------+
| |
computer 2 computer 3
python client.py python client.py
the server handles connected users and sends messages to everyone.
you need:
- python 3.11 or newer
- windows, linux, or macos
- two or more computers for a real lan test
- all computers connected to the same local network
you do not need:
- pip
- node
- npm
- a database
- an account
- an api key
- internet access
there are no third party python packages right now.
clone it:
git clone https://github.com/tavish22/lanchat.git
cd lanchator download the repo as a zip from github and extract it.
you can test everything on one computer first.
open a terminal inside the lanchat folder:
python server.pyyou should see something like:
lanchat server running on port 42691
waiting for people...
leave this terminal open.
open another terminal in the same folder:
python client.py 127.0.0.1you should get a guest name and a prompt:
you are guest1
type /help for commands
>
type a message.
because there is only one client, you won't see the message come back to yourself yet. the server is still running and accepting connections.
open a third terminal:
python client.py 127.0.0.1now you have two clients connected to the same server.
send a message from one.
the other should receive it.
this is the part lanchat was actually made for.
you need two computers connected to the same wifi/router.
open the project folder and run:
python server.pyleave it running.
open the same project on the second computer and run:
python client.pythe client will say:
looking around for lanchat...
then it should find the server automatically:
found it at 192.168.x.x:42691
and connect.
that's it.
run the same command on every other computer:
python client.pyeveryone should end up in the same chat.
sometimes windows firewall, router settings, guest wifi, or network isolation can block udp broadcasts.
don't panic.
first find the server computer's local ip address.
on the server computer:
ipconfiglook for something like:
IPv4 Address. . . . . . . . . . . : 192.168.1.42
then on the client computer run:
python client.py 192.168.1.42replace the ip with the actual address of the server.
run:
ip addror:
hostname -Ithen use the local ip with:
python client.py YOUR_IPrun:
ipconfig getifaddr en0if you're using another network interface, you may need to check ifconfig.
then:
python client.py YOUR_IPwindows may show a firewall popup the first time you run the server.
allow python through the firewall on private networks.
if you accidentally blocked it, open:
Windows Security
-> Firewall & network protection
-> Allow an app through firewall
make sure python is allowed on private networks.
don't randomly disable your firewall just to make the app work.
lanchat uses two ports:
| port | protocol | used for |
|---|---|---|
| 42691 | tcp | actual chat |
| 42690 | udp | finding the server |
these are local network ports.
the app doesn't need port forwarding on your router.
you should not expose lanchat to the public internet.
you can change the chat and discovery ports with environment variables.
chat port:
set LANCHAT_PORT=50000
python server.py$env:LANCHAT_PORT="50000"
python server.pydiscovery port:
set LANCHAT_DISCOVERY_PORT=50001
python server.py$env:LANCHAT_DISCOVERY_PORT="50001"
python server.pyif you change the discovery port, every client/server needs to use the same setting.
once you're inside the chat:
/name tavish
/who
/help
/quit
anything that isn't a command gets sent as a chat message.
lanchat/
├── client.py
├── server.py
├── discovery.py
├── protocol.py
├── config.py
├── ui.py
├── test_protocol.py
├── start_server.bat
├── requirements.txt
├── .gitignore
└── README.md
the terminal client.
it connects to the server, reads input, sends messages, and listens for messages from other people.
the main chat server.
it accepts tcp connections, keeps track of users, receives messages, and broadcasts them to everyone.
handles the little udp broadcast used to find a lanchat server automatically.
handles the message format used between clients and the server.
messages are length-prefixed json packets so tcp knows exactly where one message ends and the next one begins.
keeps the basic settings in one place.
handles the terminal output and timestamps.
a small test for the packet system.
run it with:
python test_protocol.pyyou should see:
protocol test passed
there are two parts.
the client sends a udp broadcast:
255.255.255.255:42690
the server listens for the discovery message and replies with its tcp port.
this means you don't normally need to know the server's ip beforehand.
after discovery, the client connects to the server using tcp:
server-ip:42691
tcp is used for chat because we don't want messages randomly disappearing or arriving in the wrong order.
the server then keeps a connection open for each client.
try connecting directly:
python client.py SERVER_IP
also check:
- both computers are on the same wifi
- you're not using guest wifi
- windows firewall allows python
- the server is actually running
- the server ip is correct
the server probably isn't running, the ip is wrong, or the chat port is blocked.
start:
python server.py
then try again.
something is already using port 42691.
either stop the other lanchat server or choose another chat port.
that's usually a firewall/network issue.
first try:
python client.py SERVER_IP
if that still fails, check the firewall and make sure both machines are actually on the same local network.
some school, hotel, public, and guest networks intentionally prevent devices from talking to each other.
lanchat can't bypass that.
this is a local-network project, not a production messaging service.
messages are not end-to-end encrypted.
there is no login system.
there is no authentication.
anyone who can reach the server can potentially connect.
don't run it on an untrusted network.
also don't port-forward the chat server onto the internet.
there are no dependencies to install right now.
so you can just run:
python server.pyor:
python client.pyrun the protocol test with:
python test_protocol.pystuff that could be added later:
- file drops
- typing indicators
- message history
- chat rooms
- better terminal ui
- user colors
- private messages
- reactions
- encryption
- server commands
- kick/mute controls
- tiny file sharing
- maybe voice chat if we get stupid enough
because making another todo app felt boring.
i wanted something that actually touches networking, sockets, protocols, threading, discovery, and terminal stuff.
and now two computers on the same wifi can yell at each other without the internet.
pretty sick honestly.