当前位置: 首页>>代码示例>>C#>>正文


C# Server.Listen方法代码示例

本文整理汇总了C#中Server.Listen方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Listen方法的具体用法?C# Server.Listen怎么用?C# Server.Listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server的用法示例。


在下文中一共展示了Server.Listen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ServerWillOpenSocketWhenToldToListen

        public void ServerWillOpenSocketWhenToldToListen()
        {
            var server = new Server((req, resp) => { });
            server.Listen(56565, null, null);

            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            socket.Connect("localhost", 56565);
            socket.Close();
        }
开发者ID:virajs,项目名称:firefly,代码行数:9,代码来源:ServerTests.cs

示例2: ServerWillCloseSocket

        public void ServerWillCloseSocket()
        {
            var server = new Server();
            server.Listen(56566, null, null);
            server.Close();

            Assert.Throws<SocketException>(() =>
                              {
                                  var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                                  socket.Connect("localhost", 56566);
                                  socket.Close();
                              });
        }
开发者ID:virajs,项目名称:firefly,代码行数:13,代码来源:ServerTests.cs

示例3: ServerWillEmitCloseRequest

        public void ServerWillEmitCloseRequest()
        {
            var server = new Server();
            var closed = false;
            server.OnClose(errno => closed = true);
            server.Listen(56566, null, null);

            var closedBefore = closed;
            server.Close();
            var closedAfter = closed;

            Assert.Equal(false, closedBefore);
            Assert.Equal(true, closedAfter);
        }
开发者ID:virajs,项目名称:firefly,代码行数:14,代码来源:ServerTests.cs

示例4: ServerWillEmitRequestEvent

        public void ServerWillEmitRequestEvent()
        {
            var requested = false;
            using (var server = new Server((req, resp) =>
            {
                requested = true;
                resp.Headers["Content-Type"] = "text/plain";
                resp.Headers["Connection"] = "close";
                resp.WriteHead(200, "OK");
                resp.End();
            }))
            {
                server.Listen(56567, null, null);

                var webRequest = System.Net.WebRequest.Create("http://localhost:56567");
                var webResponse = webRequest.GetResponse();

                Assert.Equal(true, requested);

            }
        }
开发者ID:virajs,项目名称:firefly,代码行数:21,代码来源:ServerTests.cs

示例5: Main

        static void Main(string[] args)
        {
            Console.WriteLine("DualSnake Server v1.0\r\nCopyright (C) Solymosi Máté 2011\r\n");
            if (args.Length > 0)
            {
                try { LoadLevel(args[0]); }
                catch { return; }
            }
            else
            {
                try { LoadLevel("Default.level"); }
                catch
                {
                    Console.WriteLine("Using built-in default map.");
                    Map = Tools.CreateDefaultMap(SnakeGame.FieldWidth, SnakeGame.FieldHeight);
                }
            }

            Server<SnakePlayer> Server = new Server<SnakePlayer>(1991);
            Server.Connected += new Server<SnakePlayer>.ConnectedDelegate(Server_Connected);
            Server.Listen();
            Console.WriteLine("\r\nListening on port 1991. Press CTRL+C to exit.");
            while (true) { System.Threading.Thread.Sleep(10000); }
        }
开发者ID:solymosi,项目名称:dualsnake,代码行数:24,代码来源:Program.cs

示例6: Main

 static void Main()
 {
     Server server = new Server();
     server.Listen();
 }
开发者ID:tomassimonavicius,项目名称:SDO,代码行数:5,代码来源:Program.cs

示例7: TextCanBeSentThroughResponse

        public void TextCanBeSentThroughResponse()
        {
            var requested = false;
            using (var server = new Server((req, resp) =>
            {
                requested = true;
                resp.Headers["Content-Type"] = "text/plain";
                resp.Headers["Connection"] = "close";
                resp.WriteHead(200, "OK");
                resp.Write("This is a triumph");
                resp.End();
            }))
            {
                server.Listen(56567, null, null);

                var webRequest = System.Net.WebRequest.Create("http://localhost:56567");
                var webResponse = webRequest.GetResponse();
                using (var stream = webResponse.GetResponseStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var text = reader.ReadToEnd();
                        Assert.Equal("This is a triumph", text);
                    }
                }

                Assert.Equal(true, requested);
            }
        }
开发者ID:virajs,项目名称:firefly,代码行数:29,代码来源:ServerTests.cs


注:本文中的Server.Listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。