Ejemplo n.º 1
0
        private static http.Server InitServer(ExpressApp app, int port)
        {
            process.stdout.write($">> Creating Server on port {port}.. ");

            try
            {
                // Create a Server:
                var server = http.createServer(app.AsCreateServerFn());

                // Assign Event Handlers:
                server.on(node.Literals.listening, () =>
                {
                    System.Console.WriteLine("[Server] Server is started!");
                });

                server.on(node.Literals.error, err =>
                {
                    System.Console.WriteLine("[Server] Error: " + err.message);
                });

                server.on(node.Literals.connection, socket =>
                {
                    System.Console.WriteLine($"[Server] Connection established from remote: {socket.remoteAddress}:{socket.remotePort}");
                });

                // Start listening on the specified port:
                server.listen(port);
                System.Console.WriteLine("Done!");

                return(server);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error: " + e.Message);
                return(null);
            }
        }