add client host parameter

This commit is contained in:
Matthieu Jolimaitre 2024-04-10 10:35:04 +02:00
parent 66c80fac5d
commit 64dbc20f4a

View file

@ -17,7 +17,7 @@ async function main() {
const args = parse_args(Deno.args);
log("Client starting.");
const interface_ = await ServerInterface.connect(args.port);
const interface_ = await ServerInterface.connect(args.host, args.port);
const display = new DisplayHandler(interface_.outputs);
new MsgHandler(interface_.inputs, display).spin();
new InputHandler(interface_.outputs).spin();
@ -29,10 +29,12 @@ async function main() {
}
function parse_args(args: string[]) {
const [port_] = args;
const [host_, port_] = args;
let host = "localhost";
if (host_ !== undefined) host = host_;
let port = 9999;
if (port_ !== undefined) port = parseInt(port_);
return { port };
return { host, port };
}
class MsgHandler {
@ -117,8 +119,8 @@ class ServerInterface {
this.outputs = outputs;
}
static async connect(port: number) {
const connection = await Deno.connect({ port });
static async connect(hostname: string, port: number) {
const connection = await Deno.connect({ hostname, port });
return await ServerInterface.init(connection);
}