https://github.com/trisha/websocket-example
Minimalistic websocket server + client
https://github.com/trisha/websocket-example
Last synced: 3 months ago
JSON representation
Minimalistic websocket server + client
- Host: GitHub
- URL: https://github.com/trisha/websocket-example
- Owner: trisha
- Created: 2024-01-29T07:40:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-14T21:25:43.000Z (12 months ago)
- Last Synced: 2025-01-10T22:15:27.896Z (5 months ago)
- Language: HTML
- Homepage:
- Size: 7.24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Context
I created this proof-of-concept (POC) because all the examples I could find online weren't working. You need both a websocket-toggled client *and* a websocket-enabled server in order for it to work, and the sample websocket server that I was trying to use (https://echo.websocket.org/) was offline at the time.# Running the websocket server
Run `npm install` to install dependenciesRun `npm start` to run the server (`index.js`), hosted at localhost:8080
You'll see an "Upgrade Required` message if you go to localhost:8080 in your browser, meaning your client has to request a websocket upgrade.
# Running the websocket interface
Confirm that the server address (wsUri) in `client.html` matches localhost:8080. Then copy the file path, and paste the file path into browser of your choice to run it locally. For me the file path is `/Users/trishapan/Documents/code/websocket-server/client.html`Et voilà! Play around with having multiple Chrome profiles open, as well as Chrome Incognito tabs (cmd+shift+N) to send messages!
P.S. You will have to refresh your HTML file/browser ever time you make a change to the client OR the server, because the server automatically resets due to nodemon watching for changes.
Client preview:
