This is a chat application that allows for users to chat via the web page and also allows for broadcast messages that are sent into the node server via a direct tcp socket as well as file tailing with those contents sent to the clients. A python script is used to demonstrate the latter capacilities.
Node.js is at the heart of this chat application. It uses express to handle user connections and to serve index.html. When a user submits a message, that message is sent to the backend node server from the client JS file. The node server will then emit (forward) that message to all connected clients.
Sitting alongside the express/http server is a simple TCP server. This TCP server is open and listening for messsages that come in over the socket. To illustrate how to use this, you'll find a simple python application. The python application connects to the open TCP port and submits a JSON message.
Another method for getting data to the clients is via file tailing. The tail npm package is used to monitor a file. When new contents are available in the file, it is captured and forwarded to the clients.
Data retention via redis.
- Clone the repo
- Start the node app:
node app.js
- In your browser, go to
http://localhost:3000
- Previously saved messages will appear, if any
- Submit chat message. Message should appear in top view of all connected clients.
- Run
client.py msg <yourmessage>
- Message generated by
client.py
should appear in top view of all connected clients. - Run
client.py stream <yourmessage>
. This will store<yourmessage>
in a file. - The new line,
<yourmessage>
, that was just stored in the file will be sent to the clients.