This commit is contained in:
Tristan B. Kildaire 2020-07-27 15:07:23 +02:00
parent e9a5af7863
commit ed2694bf35
3 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"listeners" : {
"enabled" : [],
"enabled" : ["listener1"],
"listener1" : {
"type" : "ipv4",
"domain" : "10.0.0.9:2222",

View File

@ -7,6 +7,7 @@ import std.json : JSONValue, parseJSON;
import std.conv : to;
import server.listener : ButterflyListener;
import server.listeners;
import std.string : cmp;
void main()
{
@ -47,9 +48,12 @@ private ButterflyListener[] constructListeners(JSONValue listenersBlock)
{
writeln("Constructing listener \"" ~ listener ~ "\" ...");
if(cmp(listenersBlock[listener]["type"].str(), "ipv4") == 0)
{
listeners ~= new IPv4Listener(listener, listenersBlock[listener]);
}
writeln("Listener \"" ~ listener ~ "\"constructed");
writeln("Listener \"" ~ listener ~ "\" constructed");
}
return listeners;

View File

@ -2,20 +2,22 @@ module server.listeners;
import core.thread : Thread;
import server.listener : ButterflyListener;
import std.socket : Socket, Address, SocketType, ProtocolType;
import std.socket : Socket, Address, SocketType, ProtocolType, parseAddress;
import std.json : JSONValue;
import client.client;
import std.conv : to;
public class IPv4Listener : ButterflyListener
{
private Socket serverSocket;
this(string name, string domain, JSONValue config)
this(string name, JSONValue config)
{
super(name, domain, config);
super(name, config["domain"].str(), config);
Address bindAddress = parseAddress(config["address"].str(), to!(ushort)(config["port"].str()));
Address bindAddress;
/**
* Instantiate a new Socket for the given Address
* `bindAddress` of which it will bind to.