vibe.de multiple ports.

Daniel Kozak kozzi11 at gmail.com
Wed Sep 30 14:12:46 UTC 2020


On Wed, Sep 30, 2020 at 2:40 PM seany via Digitalmars-d-learn <
digitalmars-d-learn at 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);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20200930/8c74641a/attachment.htm>


More information about the Digitalmars-d-learn mailing list