Reputation: 440
I created a server class that requires a port input in order to start listening on the given port. I am now trying to implement a "Manager" class that creates more servers but I wanted to input the node parameter in the Manager console and have the server be created already listening in that given port.
The constructor of the Server class is Node(int port). (If this is of any help)
Upvotes: 0
Views: 400
Reputation: 714
Your server application have Main
method which is entry point.
In this case, you can parse args
to passed port
.
public static void Main(string[] args) {
// no passed argument here
// we can read port here
if (args.Length == 0) {
// Console.ReadLine();
}
// we can parse args[0] as int (port)
else {
if (!int.TryParse(args[0], out int port)) {
Console.WriteLine("Not a valid port!");
return;
}
// Node creation
Node node = new Node(port);
// Do something
}
}
Let assume that your server application named server.exe
then, you can passing port by server.exe 1000
. In this case, args[0] will be "1000" (string, not integer).
Upvotes: 1