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


C# WebSocketServer.Stop方法代码示例

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


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

示例1: Main

        public static void Main(string [] args)
        {
            var wssv = new WebSocketServer (4649);
              //var wssv = new WebSocketServer (4649, true);
              //var wssv = new WebSocketServer ("ws://localhost:4649");
              //var wssv = new WebSocketServer ("wss://localhost:4649");
              #if DEBUG
              wssv.Log.Level = LogLevel.TRACE;
              #endif
              //var cert = ConfigurationManager.AppSettings ["ServerCertFile"];
              //var password = ConfigurationManager.AppSettings ["CertFilePassword"];
              //wssv.Certificate = new X509Certificate2 (cert, password);
              //wssv.KeepClean = false;
              wssv.AddWebSocketService<Echo> ("/Echo");
              wssv.AddWebSocketService<Chat> ("/Chat");
              //wssv.AddWebSocketService<Chat> ("/Chat", () => new Chat ("Anon#"));
              //wssv.AddWebSocketService<Echo> ("/エコー");
              //wssv.AddWebSocketService<Chat> ("/チャット");

              wssv.Start ();
              if (wssv.IsListening)
              {
            Console.WriteLine (
              "A WebSocket Server listening on port: {0} service paths:", wssv.Port);

            foreach (var path in wssv.WebSocketServices.ServicePaths)
              Console.WriteLine ("  {0}", path);
              }

              Console.WriteLine ("\nPress Enter key to stop server...");
              Console.ReadLine ();

              wssv.Stop ();
        }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:34,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            var config = new ServerConfig {
                Name = "SuperWebSocket",
                Ip = "Any",
                Port = 2012,
                Mode = SocketMode.Tcp,
            };

            Console.WriteLine("Starting WebSocketServer on port " + config.Port + "...");

            var socketServer = new WebSocketServer();
            socketServer.Setup(new RootConfig(), config);

            socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
            socketServer.NewSessionConnected += new SessionHandler<WebSocketSession>(socketServer_NewSessionConnected);
            socketServer.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(socketServer_SessionClosed);

            if (!socketServer.Start()) {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press 'q' key to stop it!");

            while (Console.ReadKey().KeyChar != 'q') {
                Console.WriteLine();
                continue;
            }
            socketServer.Stop();

            Console.WriteLine("\nThe server stopped!");
        }
开发者ID:Psyborx,项目名称:c-sharp-websocket-test,代码行数:34,代码来源:Program.cs

示例3: Main

        public static void Main()
        {
            var server = new WebSocketServer("127.0.0.1", 8080);
            server.Started += (sender, args) => Console.WriteLine("Server started!");
            server.Stopped += (sender, args) => Console.WriteLine("Server stopped!");

            Console.WriteLine("Tully WebSocket server at your command");
            var exit = false;
            server.Start();

            while (!exit)
            {
                var cmd = Console.ReadLine();

                switch (cmd)
                {
                    case "/exit":
                        exit = true;
                        break;
                    case "/start":
                        server.Start();
                        break;
                    case "/stop":
                        server.Stop();
                        break;
                    default:
                        Console.WriteLine("Unknown command " + cmd);
                        break;
                }
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
开发者ID:Domeee,项目名称:websockets,代码行数:34,代码来源:Program.cs

示例4: Run

        public void Run()
        {
            //websocket init
            Console.WriteLine("tetris server is starting... port:{0}", Port_WebSocket);
            var listener = new WebSocketServer();
            listener.NewMessageReceived += listener_NewMessageReceived;
            listener.NewSessionConnected += listener_NewSessionConnected;

            if (!listener.Setup(Port_WebSocket))
            {
                Console.WriteLine("failed to initialize.");
                return;
            }

            if (!listener.Start())
            {
                Console.WriteLine("failed to start.");
                return;
            }

            //transceiver init
            Console.WriteLine("transceiver is starting... port:{0}", Port_Transceiver);
            var tr = new Transceiver(null, 2013);

            isRunning = true;
            Thread th = new Thread(() =>
            {
                Packet p = new Packet();
                while (isRunning)
                {
                    p.Clear();
                    tr.Receive(ref p);

                    Console.WriteLine("received a packet: {0}", p.Peek());

                    if (conn != null)
                    {
                        try
                        {
                            conn.Send((string)p.Pop());
                        }
            #pragma warning disable 0168
                        catch (Exception ex)
                        {
                            //conn = null;
                        }
            #pragma warning restore 0168
                    }
                }
                tr.Dispose();
            });
            th.Start();

            Console.WriteLine("press enter to terminate server.");
            Console.ReadLine();

            isRunning = false;
            listener.Stop();
            Console.WriteLine("terminating server...");
        }
开发者ID:Letractively,项目名称:sod-lg-smart-tv-project,代码行数:60,代码来源:TetrisWebSocket.cs

示例5: BasicRoundTrip

		public void BasicRoundTrip()
		{
			var serializer = new JsonCommonSerializer();

			var port = new Random().Next(6000, 60000);

			var listener = new WebSocketServer("ws://localhost:" + port);
			var serverTransport = listener.GenerateTransportSource("/p1");
			var serverRouter = new DefaultMessageRouter(serverTransport, serializer);
			serverRouter.AddService<IMyService>(new MyService());
			listener.Start();

			var client = new WebSocket("ws://localhost:" + port + "/p1");
			var clientTransport = client.GenerateTransportSource();
			var clientRouter = new DefaultMessageRouter(clientTransport, serializer);
			var proxy = clientRouter.AddInterface<IMyService>();
			client.Connect();

			var result = proxy.Add(3, 4).Result;
			Assert.Equal(7, result);

			clientRouter.Dispose();
			clientTransport.Dispose();
			client.Close();

			serverRouter.Dispose();
			serverTransport.Dispose();
			listener.Stop();
		}
开发者ID:BrannonKing,项目名称:Kts.Remoting,代码行数:29,代码来源:WebsocketSharpFullCircle.cs

示例6: Main

 public static void Main(string[] args)
 {
     var wssv = new WebSocketServer("ws://127.0.0.1");
     wssv.AddWebSocketService<CatServer>("/cat");
     wssv.Start();
     Console.WriteLine("Server started");
     Console.ReadKey(true);
     wssv.Stop();
 }
开发者ID:megaton,项目名称:catsim-server,代码行数:9,代码来源:Program.cs

示例7: Main

 static void Main(string[] args)
 {
     var wssv = new WebSocketServer("ws://localhost:8181/");
     wssv.AddWebSocketService<Laputa>("/");
     Console.WriteLine("Listening...");
     wssv.Start();
     Console.ReadKey(true);
     wssv.Stop();
 }
开发者ID:hiop,项目名称:protoc_js,代码行数:9,代码来源:Program.cs

示例8: Main

        public static void Main(string [] args)
        {
            /* Single service server
              var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649");
              //var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649/Echo");
              //var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649/エコー");
              //var wssv = new WebSocketServiceHost<Echo> (4649);
              //var wssv = new WebSocketServiceHost<Echo> (4649, "/Echo");
              //var wssv = new WebSocketServiceHost<Echo> (4649, "/エコー");
              //var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649");
              //var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649/Chat");
              //var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649/チャット");
              //var wssv = new WebSocketServiceHost<Chat> (4649);
              //var wssv = new WebSocketServiceHost<Chat> (4649, "/Chat");
              //var wssv = new WebSocketServiceHost<Chat> (4649, "/チャット");
              #if DEBUG
              wssv.Log.Level = LogLevel.TRACE;
              #endif
              //wssv.KeepClean = false;

              wssv.Start ();
              Console.WriteLine (
            "WebSocket Service Host (url: {0})\n  listening on address: {1} port: {2}\n",
            wssv.Uri, wssv.Address, wssv.Port);
               */

              /* Multi services server */
              var wssv = new WebSocketServer (4649);
              //var wssv = new WebSocketServer (4649, true);
              //var wssv = new WebSocketServer ("ws://localhost:4649");
              //var wssv = new WebSocketServer ("wss://localhost:4649");
              #if DEBUG
              wssv.Log.Level = LogLevel.TRACE;
              #endif
              //var file = ConfigurationManager.AppSettings ["ServerCertFile"];
              //var password = ConfigurationManager.AppSettings ["CertFilePassword"];
              //wssv.Certificate = new X509Certificate2 (file, password);
              //wssv.KeepClean = false;
              wssv.AddWebSocketService<Echo> ("/Echo");
              wssv.AddWebSocketService<Chat> ("/Chat");
              //wssv.AddWebSocketService<Echo> ("/エコー");
              //wssv.AddWebSocketService<Chat> ("/チャット");

              wssv.Start ();
              Console.WriteLine (
            "WebSocket Server listening on port: {0} service path:", wssv.Port);
              foreach (var path in wssv.ServicePaths)
            Console.WriteLine ("  {0}", path);

              Console.WriteLine ();
              Console.WriteLine ("Press enter key to stop server...");
              Console.ReadLine ();

              wssv.Stop ();
        }
开发者ID:KingKiller,项目名称:websocket-sharp,代码行数:55,代码来源:Program.cs

示例9: Main

        public static void Main()
        {
            server = new WebSocketServer();
            server.NewMessageReceived += ServerOnNewMessageReceived;
            server.NewSessionConnected += ServerOnNewSessionConnected;

            server.Setup(4521);
            server.Start();

            Console.WriteLine("Running ... press any key to exit");
            Console.ReadKey(true);

            server.Stop();
        }
开发者ID:rosenfeldeugen,项目名称:GameOfLife,代码行数:14,代码来源:Program.cs

示例10: Main

        public static void Main(string[] args)
        {
            SteamWebAPI.SetGlobalKey("17205AAF215CAD06C29BA302971AD4F0");
            var server = new WebSocketServer("ws://" + ADDRESS);

            // Add all services here
            server.AddWebSocketService<MangoMatchService>("/match");

            server.Start();
            Console.WriteLine("Server Listening...");
            Console.ReadKey(true);
            server.Stop();
            Console.WriteLine("Server stopping...");
        }
开发者ID:Flascher,项目名称:dota-mango-server,代码行数:14,代码来源:Server.cs

示例11: Start

        internal void Start()
        {
            WebSocketServer masterServer = new WebSocketServer("ws://127.0.0.1:" + _wSGroup.GetPort());
            masterServer.AddWebSocketService<WSGroupServerWSService>("/");
            masterServer.Start();
            _wSGroup.GetLogger().Debug("Server started");

            while (!_wSGroup.GetStop())
            {
                Thread.Sleep(1000);
            }

            masterServer.Stop();
        }
开发者ID:kevoree,项目名称:kevoree-dotnet-group-ws,代码行数:14,代码来源:WSGroupServer.cs

示例12: Main

        public static void Main(string[] args)
        {
            var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
              //var wssv = new WebSocketServer<Chat>("ws://localhost:4649");

              wssv.Start();
              Console.WriteLine(
            "WebSocket Server (url: {0}) listening on port: {1}\n",
            wssv.Url, wssv.Port);

              Console.WriteLine("Press any key to stop server...");
              Console.ReadLine();

              wssv.Stop();
        }
开发者ID:JeffreyZksun,项目名称:websocket-sharp,代码行数:15,代码来源:Program.cs

示例13: Main

 static void Main(string[] args)
 {
     C.WriteLine("Loading resources...");
     Resources.Load();
     C.WriteLine("Starting server...");
     var wss = new WebSocketServer(11882);
     wss.AddWebSocketService<RunPatternService>("/run");
     wss.AddWebSocketService<ResourcesService>("/resources");
     wss.Start();
     C.WriteLine("#GServer running. Press a key to stop.");
     Console.ReadKey(true);
     C.WriteLine("Stopping...");
     wss.Stop();
     C.WriteLine("#YStopped. Have a nice day.");
 }
开发者ID:RantLang,项目名称:RantServer,代码行数:15,代码来源:Program.cs

示例14: Main

        static void Main(string[] args)
        {
            var appServer = new WebSocketServer();
            if (!appServer.Setup(44961)) throw new Exception("Failed to setup");
            if (!appServer.Start()) throw new Exception("Failed to start");
            appServer.NewDataReceived += AppServerOnNewDataReceived;
            appServer.NewMessageReceived += appServer_NewMessageReceived;
            appServer.NewSessionConnected += session => Console.WriteLine("New session connected");

            Console.WriteLine("WebSocket server started");
            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
            }

            appServer.Stop();
        }
开发者ID:xhafan,项目名称:eshop-coreddd,代码行数:17,代码来源:Program.cs

示例15: Main

        public static void Main(string[] args)
        {
            /* Single service server
              //var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649");
              var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649/Echo");
              //var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649/エコー");
              //var wssv = new WebSocketServiceHost<Echo>(4649);
              //var wssv = new WebSocketServiceHost<Echo>(4649, "/Echo");
              //var wssv = new WebSocketServiceHost<Echo>(4649, "/エコー");
              //var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649");
              //var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649/Chat");
              //var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649/チャット");
              //var wssv = new WebSocketServiceHost<Chat>(4649);
              //var wssv = new WebSocketServiceHost<Chat>(4649, "/Chat");
              //var wssv = new WebSocketServiceHost<Chat>(4649, "/チャット");
              //wssv.Sweeping = false; // Stop the sweep inactive session timer.

              wssv.Start();
              Console.WriteLine(
            "WebSocket Service Host (url: {0})\n  listening on address: {1} port: {2}\n",
            wssv.Uri, wssv.Address, wssv.Port);
               */

              // Multi services server
              var wssv = new WebSocketServer(4649);
              //var wssv = new WebSocketServer("ws://localhost:4649");
              //wssv.Sweeping = false; // Stop the sweep inactive session timer.
              wssv.AddWebSocketService<Echo>("/Echo");
              wssv.AddWebSocketService<Chat>("/Chat");
              //wssv.AddWebSocketService<Echo>("/エコー");
              //wssv.AddWebSocketService<Chat>("/チャット");

              wssv.Start();
              Console.WriteLine(
            "WebSocket Server listening on port: {0} service path:", wssv.Port);
              foreach (var path in wssv.ServicePaths)
            Console.WriteLine("  {0}", path);
              Console.WriteLine();

              Console.WriteLine("Press any key to stop server...");
              Console.ReadLine();

              wssv.Stop();
        }
开发者ID:rje,项目名称:websocket-sharp,代码行数:44,代码来源:Program.cs


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