示例#1
0
		// LibuvSharp Tcp Listener
		public static async Task LoopServer()
		{
			using (var server = new LibuvSharp.TcpListener()) {
				server.Bind(Default.IPEndPoint);
				server.Listen();

				using (var client = await server.AcceptAsync()) {
					var msg = await client.ReadStructAsync();
					Console.WriteLine("LibuvSharp: " + Encoding.Default.GetString(msg));
				}
			}
		}
示例#2
0
        // LibuvSharp Tcp Listener
        public static async Task LoopServer()
        {
            using (var server = new LibuvSharp.TcpListener()) {
                server.Bind(Default.IPEndPoint);
                server.Listen();

                using (var client = await server.AcceptAsync()) {
                    var msg = await client.ReadStructAsync();

                    Console.WriteLine("LibuvSharp: " + Encoding.Default.GetString(msg));
                }
            }
        }
示例#3
0
		public static void Main(string[] args )
		{
			Loop.Default.Run(() => {
				var listener = new TcpListener();
				listener.Bind(Default.IPEndPoint);
				listener.Listen();
				var response = Encoding.Default.GetBytes("HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello World\r\n");
				listener.Connection += () => {
					var client = listener.Accept();
					client.Data += (ArraySegment<byte> obj) => {
						client.TryWrite(response);
						client.Shutdown();
					};
					client.Resume();
				};
			});
		}
示例#4
0
		public static async Task Server()
		{
			try {
				using (var server = new TcpListener()) {
					server.Bind(Default.IPEndPoint);
					server.Listen();

					using (var client = await server.AcceptAsync()) {

						client.Write("Hello World!");
						var str = await client.ReadStringAsync();
						Console.WriteLine("From Client: {0}", str);
					}
				}
			} catch (Exception e) {
				Console.WriteLine("Server Exception:");
				Console.WriteLine(e);
			}
		}
示例#5
0
		public static async Task Server()
		{
			try {
				var server = new TcpListener();
				server.Bind(ep);
				server.Listen();

				var client = await server.AcceptAsync();

				client.Write(Encoding.ASCII, "Hello World!");
				var str = await client.ReadStringAsync();
				Console.WriteLine("From Client: {0}", str);

				client.Shutdown();
				server.Close();
			} catch (Exception e) {
				Console.WriteLine("Server Exception:");
				Console.WriteLine(e);
			}
		}