Esempio n. 1
0
		static public void Main(string[] args)
		{
			Core.Loop(async () =>
			{
				var Server = new HttpServer();
				var Router = new HttpRouter();

				Router.AddRoute("/test", async (Request, Response) =>
				{
					Response.Buffering = true;

					Response.SetHttpCode(HttpCode.OK_200);
					Response.Headers["Content-Type"] = "application/json";

					var MysqlClient = new MysqlClient("FEDORADEV", User: "******", Password: "******");
					await MysqlClient.ConnectAsync();

					foreach (var Row in await MysqlClient.QueryAsync("SELECT 1 as 'k1', 2 as 'k2', 3 * 999, 'test', 1 as 'Ok';"))
					{
						await Response.WriteAsync(Row.ToString());
					}

					await MysqlClient.CloseAsync();
				});

				// Default file serving

				Router.SetDefaultRoute(new HttpStaticFileServer(new LocalFileSystem(@"C:\projects\csharp\NodeNet\static"), Cache: true));

				Server.AddFilterLast(Router);
				await Server.ListenAsync(80, "127.0.0.1");
			});
		}
Esempio n. 2
0
		async public Task TestMethod2()
		{
			await TestTcpServer.Create(
				Server: async (Client) =>
				{
					await Task.Yield();
				},
				Client: async (TestPort) =>
				{
					var Mysql = new MysqlClient(Host: "127.0.0.1", Port: TestPort);
					await Mysql.QueryAsync("SELECT 1;");
				}
			);
		}