Skip to content

mikeesto/python-node-websocket

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

Python + Node.js + WebSocket

Remix on Glitch!

Recently I've been using Python to interact with hardware and IoT sensors. I wanted an easy way to pipe the data into a Node application. This example provides a simple structure for doing so. It could also be used for other domains in which Python is popular, such as machine learning.

python/script.py

A Python script that could be used for everything & anything. In this example it is a simple counter.

app.js

Creates a Node http server. Listens for clients connecting to the server. Sends the Python output to the client. Logs any messages received from the client. Uses ws, a popular Node.js WebSocket library.

public/js/client.js

Connects to the WebSocket server. When a message is received, updates the page. If the number received is even, sends a response back to the server. Uses the ReconnectingWebSocket library to automatically reconnect if the connection is dropped.

About

A starter template for using Python with Node.js and WebSocket

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published