RPC with Nodejs Websocket and http/2 Push Streaming, inspired from apache thrift, Grpc

{
"Login":{
"requestPayload":{
"username":"Joe",
"password":"kaihiwatari"
}
},
"GetProfile":{},
"SchemeMaster":{
"requestPayload":{
"category":"EQUITY"
}
}
}
const parserSchema = require("./ProjectParser");
const Login = require("./controllers/Login");const GetProfile = require("./controllers/GetProfile");
parserSchema.Project.CreateSchema({
"Login":{
method:Login,
timeout:100,
},
"GetProfile":{
method:GetProfile,
timeout:100,
}
});
parserSchema.Project.Use(function(req, res, next)
{
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
parserSchema.Project.Listen("http","127.0.0.1:8000");
parserSchema.Project.SetRoutePath("/");
parserSchema.Project.StartStreaming();
parserSchema.Project.CreateHttpStreaming("http","127.0.0.1:8100");
parserSchema.Project.StartHttpStreaming();
<html>    <script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
var saveData = $.ajax({
type: 'POST',
url: "http://localhost:8000",
beforeSend: function(request) {
request.setRequestHeader("Content-Type", "application/json");
},
data: JSON.stringify({
"Login":{
"requestPayload":{
"username":"sudeep.dasgupta",
"password":"kaihiwatari"
}
},
"GetProfile":{},
"SchemesMaster":{
"requestPayload":{
"category":"EQUITY"
}
}
}),
success: function(resultData)
{
console.log(resultData)
}
});
function WebSocketTest()
{
if ("WebSocket" in window)
{
// Let us open a web socket
var ws = new WebSocket("ws://localhost:8000");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send(
JSON.stringify({
"Login":{
"requestPayload":{
"username":"sudeep.dasgupta",
"password":"kaihiwatari"
}
},
"GetProfile":{},
"SchemesMaster":{
"requestPayload":{
"category":"EQUITY"
}
}
})
);
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
console.log(received_msg);
};
ws.onclose = function()
{
// websocket is closed.
console.log("Connection is closed...");
};
} else {
// The browser doesn't support WebSocket
console.log("WebSocket NOT supported by your Browser!");
}
}
WebSocketTest();
</script>
</html>
const http2 = require('http2');
function post(url, path, body)
{
const client = http2.connect(url);
const buffer = Buffer.from(JSON.stringify(body));
const req = client.request({
[http2.constants.HTTP2_HEADER_SCHEME]: "http",
[http2.constants.HTTP2_HEADER_METHOD]: http2.constants.HTTP2_METHOD_POST,
[http2.constants.HTTP2_HEADER_PATH]: `/${path}`,
"Content-Type": "application/json",
"Content-Length": buffer.length,
});
req.on('response', (headers, flags) => {
for (const name in headers) {
console.log(`${name}: ${headers[name]}`);
}
});
req.setEncoding('utf8');
var data = "";
req.on('data', (chunk) => {
console.log(chunk);
data += chunk;
});
req.end(buffer);
req.on('end', () => {
console.log(data);
client.close();
});
req.on("error",function(err)
{
console.log(err);
})
}
post("http://127.0.0.1:8100", "/", {
"Login":{
"requestPayload":{
"username":"sudeep.dasgupta",
"password":"kaihiwatari"
}
},
"GetProfile":{},
"SchemesMaster":{
"requestPayload":{
"category":"EQUITY"
}
}
});

Machine Learning | Big Data | Video Streaming | Real-Time Low Latency Apps | Product Designer | Programmer | Open Source Contributor