seriousme / opifex

MQTT Server and Client on Deno and NodeJS
MIT License
14 stars 1 forks source link

How do i import `TcpServer` from this package? #13

Open 343max opened 3 days ago

343max commented 3 days ago

I'm trying to reproduce the sample server but I can't figure out how to import the TcpServer from your package. The package exports an MqttServer but I can't find a word how to use it. Can you please provide an example how to use your module?

seriousme commented 3 days ago

Hi,

thanks for asking. The sample demoServer is an example on how to use the TcpServer. If you just want to run an MQTT server then demoServer will do the job. If you want to add custom logic on how to handle authentication and authorization then you'll want to clone and adapt the demoServer, e.g. see the conformanceServer which is a variant of the demoServer specifically for conformancetesting with IotTestWare.

The MQTTserver takes a sockConn object and will use the Readable and Writable streams in the sockConn to communicate with the network layer.

In the demoServer the sockConn is created by TcpServer using NodeJS API's , but you could also create a sockConn based on Deno API's using the TcpServer in /deno or you could base the sockConn on websocketstream (this in currently not implemented in Opifex, but should be fairly easy to add).

Or any other type of connectivity that can deliver a reliable connection and is capable of interfacing to Readable/Writable streams.

Hope this helps. Feel free to ask more questions!

Kind regards, Hans

343max commented 3 days ago

Ah. I see. Now I know what you mean. I think it would be helpful if your sample code would show directly how to use the MqttServer class instead of wrapping it in another class in a different directory. I was under the impression the API of your package expects me to use the TcpServer.

seriousme commented 3 days ago

Thanks for the feedback!

I tried at first to make the code use either the Deno or NodeJS version of TcpServer based on platform detection, but since Deno works as well with the NodeJS version I decided to skip platform detection.

I will try to document this a bit better.

Thanks again, Hans

seriousme commented 3 days ago

I have just added an architecture section to the README.

Does this help?

Kind regards, Hans

343max commented 3 days ago

I think it helps a bit. Ideally I would like a bit of example code (like the demoServer.ts) that I can just copy & paste and get started, just show me how to use the real API right away. A tiny package like yours has to prove it's usefulness really quickly. If I would have been able to get the mqttServer up and running in a few minutes I probably would be using it right now in my project. Honestly I just assumed that you forgot to export the TcpServer. I found the MqttServer class, but I couldn't find a good example and assumed TcpServer was part of the API you are providing, not example code. It makes sense for me now once I read your reply, but it really didn't occur to me before.

Does this make sense?