Skip to content
Snippets Groups Projects
Commit a8e5fee5 authored by IsolatedSushi's avatar IsolatedSushi
Browse files

Added random points again

parent a42d0902
No related branches found
No related tags found
1 merge request!10Web socket streaming
......@@ -41,14 +41,19 @@ function getProjectionPoints(call){
console.log("connected");
call.on('data',(msg)=>{
console.log(msg.hdvector);
if(msg.hdvector.length > 0){
echoPoint(call,msg.hdvector);
}
else{
sendProjectionPoints(call);
}
});
call.on('end',()=>{
console.log("end ");
});
}
function echoPoint(call, hdvector){
var response = {id : pointID, x: hdvector[0], y: hdvector[1]};
call.write(response);
......
......
......@@ -49,22 +49,22 @@ main();
wss.on('connection', function connection(_ws) {
console.log(`Client connected with websocket`);
ws = _ws;
_ws.on('message', function incoming(message) {
parseMessage(_ws, message);
ws.on('message', function incoming(message) {
parseMessage(message);
});
});
function parseMessage(_ws, message) {
function parseMessage(message) {
const jsonMessage = JSON.parse(message);
switch (jsonMessage["type"]) {
case "requestPointStream":
console.log("Requested stream");
getPointStream(_ws);
getPointStream();
break;
case "sendDataRow":
sendRowToServer(jsonMessage["row"]);
//echoPoint(ws, jsonMessage["row"]);
//echoPoint(jsonMessage["row"]);
break;
default:
console.log("Error! Unknown request:" + jsonMessage["type"]);
......@@ -73,9 +73,9 @@ function parseMessage(_ws, message) {
function echoPoint(_ws, dataRow) {
function echoPoint(dataRow) {
console.log(dataRow);
_ws.send(JSON.stringify({
ws.send(JSON.stringify({
"id": dataRow[0]
, "x": dataRow[1],
"y": dataRow[2]
......@@ -83,12 +83,12 @@ function echoPoint(_ws, dataRow) {
}));
}
function getPointStream(_ws) {
function getPointStream() {
var trainingSetRow = {id: "0",hdvector: null};
call.write(trainingSetRow);
console.log("stream")
}
function sendRowToServer(row) {
var hdvector = [];
row.forEach((el) => {
......@@ -99,9 +99,7 @@ function sendRowToServer(row) {
call.write(trainingSetRow);
}
function sendDataStreamToClient(data, ws) {
function sendDataStreamToClient(data) {
var list = data.toString().trim().split("\n");
for (var i = 0; i < list.length; i++) {
try {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment