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


C# WebSocketServer.Setup方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            //int port = int.Parse(args[0]);
            int port = 443;
            ServerConfig serverConfig = new ServerConfig
            {
                Name = "SecureSuperWebSocket",
                Ip = "Any",
                Port = port,
                MaxRequestLength = 10485760,
                SendingQueueSize = 500,
                ReceiveBufferSize = 2050 * 1024,
                //SendBufferSize = 600 * 1024,
            };

            socketServer = new WebSocketServer();
            socketServer.NewSessionConnected += SocketServer_NewSessionConnected;
            socketServer.NewDataReceived += SocketServer_NewDataReceived;
            //socketServer.NewMessageReceived += SocketServer_NewMessageReceived;
            socketServer.Setup(serverConfig);
            socketServer.Start();

            Console.WriteLine("Server is running on port {0} ...", port);

            Console.ReadKey();
        }
开发者ID:Jackie-Innover,项目名称:3VR,代码行数:26,代码来源:Program.cs

示例2: WebSocketInterface

        public WebSocketInterface(int port, Session session)
        {
            _session = session;
            var translations = session.Translation;
            _server = new WebSocketServer();
            _websocketHandler = WebSocketEventManager.CreateInstance();
            var setupComplete = _server.Setup(new ServerConfig
            {
                Name = "NecroWebSocket",
                Ip = "Any",
                Port = port,
                Mode = SocketMode.Tcp,
                Security = "tls",
                Certificate = new CertificateConfig
                {
                    FilePath = @"cert.pfx",
                    Password = "necro"
                }
            });

            if (setupComplete == false)
            {
                Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error);
                return;
            }

            _server.NewMessageReceived += HandleMessage;
            _server.NewSessionConnected += HandleSession;

            _server.Start();
        }
开发者ID:RedNax67,项目名称:NecroBot,代码行数:31,代码来源:WebSocketInterface.cs

示例3: 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

示例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: WebSocketInterface

        public WebSocketInterface(int port)
        {
            _server = new WebSocketServer();
            var setupComplete = _server.Setup(new ServerConfig
            {
                Name = "NecroWebSocket",
                Ip = "Any",
                Port = port,
                Mode = SocketMode.Tcp,
                Security = "tls",
                Certificate = new CertificateConfig
                {
                    FilePath = @"cert.pfx",
                    Password = "necro"
                }
            });

            if (setupComplete == false)
            {
                Logger.Write($"Failed to start WebSocketServer on port : {port}", LogLevel.Error);
                return;
            }

            _server.NewMessageReceived += HandleMessage;
            _server.NewSessionConnected += HandleSession;

            _server.Start();
        }
开发者ID:CapnSplinters,项目名称:d,代码行数:28,代码来源:WebSocketInterface.cs

示例6: socketServer_Initialize

        static void socketServer_Initialize()
        {
            // Initialize the server object
            SuperWebSocket.WebSocketServer socketServer = new WebSocketServer ();

            // Initialize basic server configurations
            SuperSocket.SocketBase.Config.RootConfig socketRootConfig = new SuperSocket.SocketBase.Config.RootConfig ();
            SuperSocket.SocketBase.Config.ServerConfig socketServerConfig = new SuperSocket.SocketBase.Config.ServerConfig ();
            SuperSocket.SocketEngine.SocketServerFactory socketServerFactory = new SuperSocket.SocketEngine.SocketServerFactory ();

            // Set the name, IP address and port number which the server is started on
            socketServerConfig.Name = "Quetzalcoatl Server";
            socketServerConfig.Ip = "127.0.0.1";
            socketServerConfig.Port = 1620;

            // Print boilerplate text when the console is first displayed
            logConsoleBoilerplate ();

            // Create the server using the specifications created above
            // If the server fails to start, write to the console
            if (!socketServer.Setup (socketRootConfig, socketServerConfig, socketServerFactory)) {
                Console.WriteLine ("Failed to initialize server at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port);
                Console.ReadKey ();
                return;
            }

            // Start the server
            // If the server fails to start, write to the console
            if (!socketServer.Start ()) {
                Console.WriteLine ("Server was successfully initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port +
                " but failed to start. Ensure that no processes are currently running at the same address.");
                Console.ReadKey ();
                return;
            }

            // Notify the user that the server has successfully started and is awaiting connections
            Console.WriteLine ("Server initialized at ws[s]://" + socketServer.Config.Ip + ":" + socketServer.Config.Port + " at " + socketServer.StartedTime);
            Console.WriteLine ("Awaiting client connections...");
            Console.WriteLine ();

            // Bind listeners for server events
            socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string> (socketServer_NewMessageReceived);
            socketServer.NewSessionConnected += socketServer_NewSessionConnected;
            socketServer.SessionClosed += socketServer_SessionClosed;

            // Nullify all console inputs except for when the user types "exit"
            while (Console.ReadLine () != "exit") {
                continue;
            }

            // Properly shutdown the server by waiting on the buffer and freeing all used ports
            socketServer_Shutdown (socketServer);

            return;
        }
开发者ID:kenlimmj,项目名称:quetzalcoatl,代码行数:55,代码来源:Program.cs

示例7: Main

 static void Main(string[] arguments)
 {
     WebSocketServer server = new WebSocketServer();
     server.NewSessionConnected += new SessionHandler<WebSocketSession>(OnConnect);
     server.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(OnDisconnect);
     server.NewMessageReceived += new SessionHandler<WebSocketSession, string>(OnMessage);
     server.Setup(81);
     server.Start();
     ManualResetEvent resetEvent = new ManualResetEvent(false);
     resetEvent.WaitOne();
 }
开发者ID:epicvrvs,项目名称:Voiddekk,代码行数:11,代码来源:Program.cs

示例8: Setup

 public virtual void Setup()
 {
     m_WebSocketServer = new WebSocketServer(new BasicSubProtocol("Basic", new List<Assembly> { this.GetType().Assembly }));
     m_WebSocketServer.Setup(new ServerConfig
     {
         Port = 2012,
         Ip = "Any",
         MaxConnectionNumber = 100,
         Mode = SocketMode.Tcp,
         Name = "SuperWebSocket Server"
     }, logFactory: new ConsoleLogFactory());
 }
开发者ID:kengoemon,项目名称:WebSocket4Net,代码行数:12,代码来源:JsonWebSocketTest.cs

示例9: MainServer

 public MainServer(IPAddress address, int port)
 {
     server = new WebSocketServer();
     //Events
     server.Setup(2480);
     server.NewSessionConnected += new SessionHandler<WebSocketSession>(OnConnected);
     server.SessionClosed += new SessionHandler<WebSocketSession,CloseReason>(OnDisconnect);
     //server.NewRequestReceived += new RequestHandler<WebSocketSession,SuperWebSocket.Protocol.IWebSocketFragment>(OnConnect);
     server.NewMessageReceived += new SessionHandler<WebSocketSession,string>(OnMessage);
     server.Start();
     MainGame = new Game();
     MainGame.StartGame();
 }
开发者ID:Half-Shot,项目名称:gmud,代码行数:13,代码来源:MainServer.cs

示例10: StartSuperWebSocketByProgramming

        public void StartSuperWebSocketByProgramming()
        {
            var socketServer = new WebSocketServer();

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

            socketServer.Setup(port);

            m_Bootstrap = new DefaultBootstrap(new RootConfig(), new IWorkItem[] { socketServer });

            m_Bootstrap.Start();
        }
开发者ID:smeshlink,项目名称:CoAP.Proxy,代码行数:14,代码来源:WebSocketService.cs

示例11: Main

        static void Main()
        {
            try
            {
                SingleInstanceChecker.checkThePowerRunning();
                tomcatController = new EmbeddedTomcatController();
                nativeID = Guid.NewGuid();
                portalID = Guid.NewGuid();
                websocketserver = new WebSocketServer();
                int port = Int32.Parse(ConfigurationManager.AppSettings["WebSocketPort"]);
                if (!websocketserver.Setup(port))
                {
                    throw new Exception("ERROR:" + port + " already used!");
                }

                for (int i = 0; i < 3; i++ )
                {
                    if (!websocketserver.Start())
                    {
                        EmbeddedTomcatController.killExist();
                        continue;
                    }
                    else {
                        break;
                    }
                    throw new Exception("ERROR:Failed to start server!");
                }

                websocketserver.NewMessageReceived += websocketserver_NewMessageReceived;
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                MessageBox.Show(e.Message);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            tomcatController.startTomcat();

            nativeContainer = new NativeContainer();
            nativeContainer.FormClosing += nativeContainer_FormClosing;
            splash = new SplashForm();
            nativeContainer.Splash = splash;
            splash.start();
            nativeContainer.initPortalKitUrl();
            Application.Run(splash);
        }
开发者ID:etp-work,项目名称:ThePower,代码行数:50,代码来源:Program.cs

示例12: 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

示例13: WebSocket

 public WebSocket()
 {
     _webSocketServer = new WebSocketServer();
     _webSocketServer.NewMessageReceived += _webSocketServer_NewMessageReceived;
     _webSocketServer.NewSessionConnected += _webSocketServer_NewSessionConnected;
     _webSocketServer.Setup(new RootConfig(), new ServerConfig
     {
         Port = 2013,
         Ip = "Any",
         MaxConnectionNumber = 10000,
         Mode = SocketMode.Async,
         Name = "MAGUS Async Core"
     }, SocketServerFactory.Instance);
 }
开发者ID:welsen,项目名称:HTML5Magus,代码行数:14,代码来源:WebSocket.cs

示例14: Setup

        protected void Setup(WebSocketServer websocketServer, Action<ServerConfig> configurator)
        {
            var rootConfig = new RootConfig { DisablePerformanceDataCollector = true };
            websocketServer.NewSessionConnected += new SessionHandler<WebSocketSession>(m_WebSocketServer_NewSessionConnected);
            websocketServer.SessionClosed += new SessionHandler<WebSocketSession, CloseReason>(m_WebSocketServer_SessionClosed);

            var config = new ServerConfig();
            configurator(config);

            var ret = websocketServer.Setup(rootConfig, config, null, null, new ConsoleLogFactory(), null, null);

            Assert.IsTrue(ret);

            m_WebSocketServer = websocketServer;
        }
开发者ID:2594636985,项目名称:SuperWebSocket,代码行数:15,代码来源:WebSocketRawTest.cs

示例15: WebSocketCoreBusServer

 public WebSocketCoreBusServer(int listenPort, ICoreBusClientIdExtractor coreBusClientIdExtractor = null)
     : base(coreBusClientIdExtractor)
 {
     _appServer = new WebSocketServer();
     if (!_appServer.Setup(listenPort))
     {
         throw new Exception("Failed to setup WebSocketServer");
     }
     if (!_appServer.Start())
     {
         throw new Exception("Failed to start WebSocketServer");
     }
     _appServer.NewMessageReceived += _onNewMessageReceived;
     _appServer.SessionClosed += _onSessionClosed;
 }
开发者ID:xhafan,项目名称:eshop-coreddd,代码行数:15,代码来源:WebSocketCoreBusServer.cs


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