Generate ClientHello and ServerHello using node - node.js

I would like to generate ClientHello and ServerHello messages using NodeJs for testing purposes.
Is there an easy way to generate these messages using NodeJS API (the HTTPS all ready doing it but I can't find where).
If I can't use an existing API then how do I create the simplest messages according to the RFC using NodeJS (How to build the messages in a Buffer correctly)

Related

Can I use STOMP in nodejs without message broker?

I'm working on creating mock sever for my Angular application. On frontend I have library for STOMP. And regularly my frontend communicates with Api written in Java.
But additionally I start mock nodejs api which returns hard coded Json files when remote server is down.
Now I'm trying to write mock nodejs websockets server which will community with Angular client when remote server is down. But I would like to keep it simple
I found StompJs library but seems like it needs STOMP message broker (like Rabbit?). It's seems to me a bit complicated for mock server. Is there any option to skip this broker step and keep it as simple as possible?

Does AWS ApiGateway Socket Splits Messages at 4 KB?

I'm trying to implement WebRTC Signalling Server using AWS ApiGateway with javascript in order to connect 2 clients (Client A - Web Browser; Client B - Unreal Engine's PixelStreaming Plugin).
(Note: For this implementation I'm not using the signalling sever implementation provided by Unreal, but I'm creating a replacement implementation using AWS ApiGateway)
At first I connect successfully both clients to the Api Gateway WebSocket sever and setup the required configuration.
Then I'm generating the WebRTC "offer" from the browser (Client A) and send it using method ApiGatewayManagementApiClient::PostToConnectionCommand (JS AWS SDK v3) via Lambda to the receiver's ConnectionID (Client B). I expect when the receiver (Client B) get the offer to generate an "answer". Instead of an answer from Client B I get the following error:
Error: Failed to parse SS message ...<message-chunk>...
In the logs I get this error 2 times but with different chunks of my offer (first beginning of the JSON and second somewhere in the middle). This lead me to believe that the message got split, so I tried removing parts of the JSON (shorten it) until I stop getting the error. Doing this I found that this error disappears when the exact length of the JSON message is 4096 chars (4 KB). When I send event one byte over this I get the error (2 times).
According to AWS documentation they have a maximum frame size of 32 KB. My full message is around 7 KB, so I expect that it is going to be sent at once. Unfortunately this doesn't seem to be the case my message is split to 4 KB mark.
I have working implementation of the exact same case in NodeJS and building a custom server with the ws library. Inside this implementation everything is working correctly (my 7 KB offer get delivered in once piece and I receive answer and the connection is initiated without errors). I send "offer" and then receive "answer" back.
I've used wscat to connect to both servers (the NodeJS and the ApiGateway) assuming the role of Client B and I got both "offers". Then I compared them
and they are exactly the same. (In wscat the message doesn't look to be split, but I assume that they concat the chunks before showing it.)
Based on that I can assert that I'm configuring the clients properly and that the "offer" is good to receive "answer". The only difference is that if I send the offer from the NodeJS I receive answer and all works, but if I send exactly the same offer from AWS ApiGateway I got error that the data cannot be parsed (because it is split in 4 KB chunks).
I have spent 3 days trying to resolve this issue and I'm certain that everything I send and the way I send it is correct. So I come to conclusion that I for some reason hit some limit in AWS API Gateway or Lambda (I saw that Lambda has 4 KB limit on environment variables, but I'm not using them so it should not be related) which causes my message to be split in parts. This causes the Unreal's Pixel Streaming Plugin to try deserialize the JSON in chunks instead of the whole JSON message at once and this results in 2 errors that the data cannot be parsed.
I cannot change the code of the client to first wait all the chunks to arrive and then process it. I have to use it "as is". (It is a plugin and it is written in C++)
I also tried to relay the API API Gateway Socket Message via NodeJS client and then to create a NodeJS Web Socket server connect the Unreal Engine Plugin to my NodeJS server and forward the message via it to the Unreal Engine Plugin. (AWS -> NodeJS Client -> NodeJS Server -> Unreal instead of AWS -> Unreal). This variant is working correctly without problem and I receive answer. The problem is that I introduce an additional NodeJS client and Server which beats the purpose of using API Gateway at first place...
So my question is: Is is possible that AWS API Gateway is splitting my message in 4KB chunks (or Lambda does it) and if it is so is it possible to somehow increase this limit so I receive the whole message at once instead?
I can provide code in case it is needed, but I don't think the problem is related to the concrete implementation.

MQTT server in Haskell

I would like to implement an MQTT server in Haskell.
I already have a HTTP REST server made in Haskell and would like to add some MQTT endpoints to that server.
For instance, there is an endpoint POST /foo, allowing users to send some information that will be stored in a Mongo DB. I would like to add an MQTT endpoint: if someone performs a PUBLISH with topic "/foo", the data will be stored to the same Mongo database, using the same internal functions than the POST.
Similarly for the SUBSCRIBE, the data should come from the backend database.
I saw http://hackage.haskell.org/package/mqtt-0.1.1.0
and
https://github.com/lpeterse/haskell-hummingbird
But I'm not sure if they are useable as a library to create the endpoints with specific callbacks.
So this is a two-fold question:
Any feedback on implementing MQTT endpoints in Haskell?
Is merging an HTTP and MQTT servers a good idea?
After some investigation, here are my findings on MQTT in Haskell:
First library I found is http://hackage.haskell.org/package/mqtt-hs. However it is buggy and not maintained anymore.
I'm now using http://hackage.haskell.org/package/net-mqtt, which works well.
I also understood that I didn't need to make a MQTT server: I just need to develop a client! My MQTT client will subscribe on a standard MQTT server (Mosquitto), and sink the data received in my database.
Another pain point of MQTT is the authentication/authorization. My server uses Keycloak for access control, while Mosquitto uses a static ACL file. I solved this problem by developing an authorization proxy for MQTT: the proxy sits in front of Mosquitto and filter the requests, based on Keycloak decisions.

Node.js pipelining HTTP client agent?

The HTTP client built into Node.js doesn't seem to support pipelining requests. However, it occurred to me that it may be possible to create an Agent that sets up pipelining in the background. There may be issues getting the response data back the way it should be, but perhaps the Agent could fake out some socket objects to make the HTTP client work like normal?
Has this been done? Alternatively, is there an alternative HTTP client that is a drop-in replacement for the main that supports pipelining? (Ultimately, I'd like to use it with the AWS SDK, so it needs to be compatible.)

Connect node.js and signalr via sockets

Is there anyway to send data though sockets from Node.JS to SignalR? I have a Node.JS app that sends realtime information as JSON format. The other app it's an MVC C# app that uses SignalR to send the data to the client via socket. I want tosen data from de nodejs to signalr and signal send that info to the client.
You might consider better solution for internal communication between processes. SignalR is meant to be used between .Net server and client using different authentication, handshake, protocol and network layer methods, which is inefficient for internal server communication.
Take a look on ZeroMQ, is well simple and very easy to use tool, meant especially for such cases. It has bindings for most languages including .Net and node.js.
There is js client for browser to communicate with Signal R server.
http://www.nuget.org/packages/SignalR.Js
You probably can extract js file from it and run from Node.js.
And probably standard Socket.IO will just work, you need to subscribe to proper events and go.
If you want a node.js client for signalR that doesn't require jQuery I started this one. It intentionally only supports websockets.
https://npmjs.org/package/signalr-client

Resources