digitalmars.D.learn - vibe.de multiple ports.
- seany (25/25) Sep 30 2020 Hello
- Daniel Kozak (3/21) Sep 30 2020 Why? I do not see any reason for that.
- seany (6/37) Sep 30 2020 to separate the messages from the IoT responses quickly and
- Daniel Kozak (21/27) Sep 30 2020 Ok as Adam said you can do something like this:
- aberba (12/52) Sep 30 2020 What you are doing, if I understand you well, is a way of scaling
- Adam D. Ruppe (5/12) Sep 30 2020 If you loop this section it should listen to each port. This is
Hello I am trying to use this example for a iot application: https://aberba.com/2018/using-vibe-d-web-interface/ The code i use is: ushort port = 5504; void main(char[][] args) { auto router = new URLRouter; router.post("/archive", &savedata); router.get("/archive", &savedata); auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "0.0.0.0"]; listenHTTP(settings, router); runApplication(); } This is fine. But now that we have ~ 100 IoT devices in the field, I would like to assign each a new port. The devices should be communicating over HTTP as the vendor software running thereupon uses http. What is the best practice to make a vibe.d server listen to multiple ports? Make a loop scanning each loop seems wasteful. Is there a function in vibe.d that can take multiple ports, and launch a set of threads assigned to each port? Thank you
Sep 30 2020
Dne st 30. 9. 2020 13:25 u=C5=BEivatel seany via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> napsal:Hello I am trying to use this example for a iot application: https://aberba.com/2018/using-vibe-d-web-interface/ The code i use is: ushort port =3D 5504; void main(char[][] args) { auto router =3D new URLRouter; router.post("/archive", &savedata); router.get("/archive", &savedata); auto settings =3D new HTTPServerSettings; settings.port =3D port; settings.bindAddresses =3D ["::1", "0.0.0.0"]; listenHTTP(settings, router); runApplication(); } This is fine. But now that we have ~ 100 IoT devices in the field, I would like to assign each a new port.Why? I do not see any reason for that.
Sep 30 2020
On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak wrote:Dne st 30. 9. 2020 13:25 uživatel seany via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> napsal:to separate the messages from the IoT responses quickly and forward them to different programs, and to have the capability in hand, so that when later i have an idea to exploit the capability, I can also do it.Hello I am trying to use this example for a iot application: https://aberba.com/2018/using-vibe-d-web-interface/ The code i use is: ushort port = 5504; void main(char[][] args) { auto router = new URLRouter; router.post("/archive", &savedata); router.get("/archive", &savedata); auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "0.0.0.0"]; listenHTTP(settings, router); runApplication(); } This is fine. But now that we have ~ 100 IoT devices in the field, I would like to assign each a new port.Why? I do not see any reason for that.
Sep 30 2020
On Wed, Sep 30, 2020 at 2:40 PM seany via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak wrote: to separate the messages from the IoT responses quickly and forward them to different programs, and to have the capability in hand, so that when later i have an idea to exploit the capability, I can also do it.Ok as Adam said you can do something like this: void main() { immutable ushort startPort = 5500; import std.range : iota; foreach (ushort port; iota!(ushort,ushort)(startPort, startPort + 100)) { auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "127.0.0.1"]; listenHTTP(settings, &hello); } runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { import std.conv : to; res.writeBody(req.fullURL.port.to!string); }
Sep 30 2020
On Wednesday, 30 September 2020 at 12:38:10 UTC, seany wrote:On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak wrote:What you are doing, if I understand you well, is a way of scaling the server to handle high amount of traffic. If that's right, then I'm not sure how the number of PORT is the issue. Irrespective of the port, the server resources remains the same. And if that's the case, then you might need a load balancer (or use nginx or any of the options I've used in my projects). In that case, you run multiple versions of the server in stateless environments... scaled up or down on demand. -------- Been a long while since I wrote some vibe.d tutorials though :)Dne st 30. 9. 2020 13:25 uživatel seany via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> napsal:to separate the messages from the IoT responses quickly and forward them to different programs, and to have the capability in hand, so that when later i have an idea to exploit the capability, I can also do it.Hello I am trying to use this example for a iot application: https://aberba.com/2018/using-vibe-d-web-interface/ The code i use is: ushort port = 5504; void main(char[][] args) { auto router = new URLRouter; router.post("/archive", &savedata); router.get("/archive", &savedata); auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "0.0.0.0"]; listenHTTP(settings, router); runApplication(); } This is fine. But now that we have ~ 100 IoT devices in the field, I would like to assign each a new port.Why? I do not see any reason for that.
Sep 30 2020
On Wednesday, 30 September 2020 at 11:23:59 UTC, seany wrote:auto router = new URLRouter; router.post("/archive", &savedata); router.get("/archive", &savedata); auto settings = new HTTPServerSettings; settings.port = port; settings.bindAddresses = ["::1", "0.0.0.0"]; listenHTTP(settings, router);If you loop this section it should listen to each port. This is just a setup loop, it wouldn't actually be wasteful once it is running. (I think, I don't really know vibe super well)
Sep 30 2020