Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Websocket data streaming #145

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

[WIP] - Websocket data streaming #145

wants to merge 18 commits into from

Conversation

kylemath
Copy link
Owner

@kylemath kylemath commented Mar 8, 2020

Used a simplified version of the code and a single module as a more simple way to test the streaming,

Taking over from closed PR:
#144

@kylemath kylemath requested a review from korymath March 8, 2020 05:40
@kylemath
Copy link
Owner Author

kylemath commented Mar 8, 2020

change ln 223 of pageSwitcher.js to your local IP address

var socket = await io.connect('##.#.#.##:8080');

@kylemath
Copy link
Owner Author

kylemath commented Mar 8, 2020

Seems to be connecting to the socket now, but still can't seem to access data from terminal with nc, iocat or websocat

@korymath
Copy link
Collaborator

korymath commented Mar 8, 2020

Thank you for the simplification.

I am unclear how to reproduce this:

Seems to be connecting to the socket now

What does that mean?

@korymath
Copy link
Collaborator

korymath commented Mar 8, 2020

Fixes to build and test socket connections.

Fix: L46 in index.html was calling the socket javascript

<script src="/socket.io/socket.io.js"></script>

We want to use react/node to handle our package calls, especially for the server.

Need to install socket.io

yarn add socket.io

Socket.io allows for allows synchronized communication to take place simply within your app, which means real-time communication!

It is built on WebSockets, which allows synchronized bilateral exchange between the client and the server.
WebSocket is an innovation that allows a sort of tube of communication that remains open between the client and the server

That is, the socket requires a server and a client.

Building the Server

The server centralizes and manages the connections of the different clients who are connected to the website

Building the Client

The client connects to the server and displays results in the browser.

References:
socketio/socket.io#3342 (comment)
https://stackoverflow.com/questions/52616766/socket-io-module-not-found-cant-resolve-uws-in-c-node-modules-engine
https://github.com/socketio/socket.io
https://www.valentinog.com/blog/socket-react/
https://openclassrooms.com/en/courses/2504541-ultra-fast-applications-using-node-js/2505653-socket-io-let-s-go-to-real-time

@korymath
Copy link
Collaborator

korymath commented Mar 8, 2020

As per:
https://socket.io/get-started/chat/ and yeet example, let's move to express.
More complex server, means we have to migrate from create-react-app to express.

Install express

yarn add express

Edit the package.json so that the start script runs node and not react-scripts

"start": "node server.js",

Then rebuild the site. Note, with express we will have to rebuild each time.

yarn build

Then restart the site, and it is running with the explicit express server.

Then we need to integrate Socket.IO to the server code.

https://dev.to/captainpandaz/a-socket-io-tutorial-that-isn-t-a-chat-app-with-react-js-58jh

io.emit('some event', { someProperty: 'some value', otherProperty: 'other value' }); // This will emit the event to all connected sockets

From: https://socket.io/docs/

What Socket.IO is not
Socket.IO is NOT a WebSocket implementation. Although Socket.IO indeed uses WebSocket as a transport when possible, it adds some metadata to each packet: the packet type, the namespace and the packet id when a message acknowledgement is needed. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a WebSocket server either. Please see the protocol specification here.

// WARNING: the client will NOT be able to connect!
const client = io('ws://echo.websocket.org');

So, build a simple socketio client to test socket communication.
Install the simple python client here: https://github.com/korymath/eegedu_client

@kylemath kylemath changed the title [WIP] - Minimize to one spectra module to create websocket streaming tool [WIP] - Websocket data streaming Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants