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


C# Fleck.WebSocketServer类代码示例

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


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

示例1: InitializeListener

        public void InitializeListener()
        {
            var server = new WebSocketServer("ws://localhost:8989/FileTail");

            server.Start(socket =>
            {
                socket.OnOpen = () => Console.WriteLine("Open!");
                socket.OnClose = () => Console.WriteLine("Close!");
                socket.OnMessage = message => socket.Send(message);
            });

            //var listener = new TcpListener(IPAddress.Loopback, 8989);
            //try
            //{
            //    listener.Start();
            //    using (var client = listener.AcceptTcpClient())
            //    using (var stream = client.GetStream())
            //    using (var reader = new StreamReader(stream))
            //    using (var writer = new StreamWriter(stream))
            //    {
            //        writer.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake");
            //        writer.WriteLine("Upgrade: WebSocket");
            //        writer.WriteLine("Connection: Upgrade");
            //        writer.WriteLine("WebSocket-Origin: http://localhost:50695");
            //        writer.WriteLine("WebSocket-Location: ws://localhost:8989/websession");
            //        writer.WriteLine("");
            //    }
            //    listener.Stop();
            //}
            //catch
            //{ }
        }
开发者ID:jamessantiago,项目名称:jamescms,代码行数:32,代码来源:WebSocketListener.cs

示例2: InitializeServer

        private static void InitializeServer()
        {
            var server = new WebSocketServer("ws://localhost:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("Connected to " + socket.ConnectionInfo.ClientIpAddress);
                    _clients.Add(socket);
                };

                socket.OnClose = () =>
                {
                    Console.WriteLine("Disconnected from " + socket.ConnectionInfo.ClientIpAddress);
                    _clients.Remove(socket);
                };

                socket.OnMessage = message =>
                {
                    Console.WriteLine(message);
                };
            });

            _serverInitialized = true;

            Console.ReadLine();
        }
开发者ID:Vangos,项目名称:KinectHtml5,代码行数:28,代码来源:Program.cs

示例3: Run

        public void Run(string serverUrl)
        {
            var server = new WebSocketServer(serverUrl);
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    onClientConnected(socket);
                };

                socket.OnClose = () =>
                {
                    onClientDisconnected(socket, null);
                };

                socket.OnMessage = (message) =>
                {
                    onClientMessage(socket, message, null);
                };

                socket.OnBinary = (message) =>
                {
                    onClientMessage(socket, message, null);
                };
            });
        }
开发者ID:HclX,项目名称:HomeLink,代码行数:26,代码来源:Proxy.cs

示例4: Main

        static void Main(string[] args)
        {
            var server = new WebSocketServer("ws://localhost:8181");
            server.Start(socket =>
            {
                socket.OnOpen = () => 
                    {
                        Console.WriteLine("Open: " + socket.ConnectionInfo.Id);
                    };
                socket.OnClose = () => 
                    {
                        Console.WriteLine("Close: " + socket.ConnectionInfo.Id);

                        ChatServer.Instance.ClientLost(socket);
                    };
                socket.OnMessage = message =>
                {
                    Console.WriteLine("Message: " + socket.ConnectionInfo.Id);
                    Console.WriteLine("    " + message);

                    ChatServer.Instance.Accept(socket, message);
                };
            });

            Console.ReadLine();
        }
开发者ID:oricalvo,项目名称:course-advfed-sap-2015-07,代码行数:26,代码来源:Program.cs

示例5: InitializeConnection

        private static void InitializeConnection()
        {
            var server = new WebSocketServer("ws://0.0.0.0:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    _clients.Add(socket);
                };

                socket.OnClose = () =>
                {
                    _clients.Remove(socket);
                };

                socket.OnMessage = message =>
                {
                    switch (message)
                    {
                        case "Color":
                            _mode = Mode.Color;
                            break;
                        case "Depth":
                            _mode = Mode.Depth;
                            break;
                        default:
                            break;
                    }

                    Console.WriteLine("Switched to " + message);
                };
            });
        }
开发者ID:dschie,项目名称:Kinect-HTML5,代码行数:34,代码来源:Program.cs

示例6: Init

        public void Init(string port)
        {
            FleckLog.Level = LogLevel.Warn;
            _allSockets = new List<IWebSocketConnection>();
            var websocketaddr = "ws://127.0.0.1:" + port;
            Logger.WriteMinorEvent("Attempting to open a WebSocketServer on " + websocketaddr);
            _server = new WebSocketServer(websocketaddr);

            try
            {
                _server.Start(socket =>
                {
                    socket.OnOpen = () =>
                    {
                        Debug.WriteLine("Backend received an request to open a BloomWebSocketServer socket");
                        _allSockets.Add(socket);
                    };
                    socket.OnClose = () =>
                    {
                        Debug.WriteLine("Backend received an request to close  BloomWebSocketServer socket");
                        _allSockets.Remove(socket);
                    };
                });
            }
            catch (SocketException ex)
            {
                Logger.WriteEvent("Opening a WebSocketServer on " + websocketaddr + " failed.  Error = " + ex);
                ErrorReport.NotifyUserOfProblem(ex, "Bloom cannot start properly (cannot set up some internal communications){0}{0}" +
                    "What caused this?{0}" +
                    "Possibly another version of Bloom is running, perhaps not very obviously.{0}{0}" +
                    "What can you do?{0}" +
                    "Click OK, then exit Bloom and restart your computer.{0}" +
                    "If the problem keeps happening, click 'Details' and report the problem to the developers.", Environment.NewLine);
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:35,代码来源:BloomWebSocketServer.cs

示例7: APIServer

 private APIServer() 
 {
     stopwatchOffset = 0;
     trackTime = new Stopwatch();
     ip = getIpAddress();
     server = new WebSocketServer("ws://" + ip + ":" + API_PORT);
 }
开发者ID:joshuaegclark,项目名称:SAMSS6.0,代码行数:7,代码来源:APIServer.cs

示例8: ChatHandler

        public ChatHandler()
        {
            chatSocketList = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://localhost:5002/chat");
            server.Start(socket =>
            {
                socket.OnOpen = () => {
                    Console.WriteLine("User connected to Chat");
                    chatSocketList.Add(socket);
                    //socket.Send(JsonConvert.SerializeObject(Main.ludo.Chat));
                };

                socket.OnClose = () => {
                    chatSocketList.Remove(socket);
                };

                socket.OnMessage = message =>
                {
                    Console.WriteLine("[ChatHandler] Incoming: " + message);
                    Message msg = JsonConvert.DeserializeObject<Message>(message);
                    msg.TimeStamp = DateTime.Now;
                    Main.ludo.Chat.Add(msg);
                    foreach (var s in chatSocketList.ToList())
                    {
                        s.Send(JsonConvert.SerializeObject(msg));
                    }
                };
            });
        }
开发者ID:Cir0X,项目名称:ludo,代码行数:29,代码来源:ChatHandler.cs

示例9: Start

        public void Start()
        {
            List<IWebSocketConnection> sockets = new List<IWebSocketConnection>();
            Fleck.WebSocketServer server = new Fleck.WebSocketServer("ws://127.0.0.1:8181");

            server.Start(socket =>
                {
                    socket.OnOpen = () =>
                        {
                            Console.WriteLine("Connection open.");
                            sockets.Add(socket);
                        };
                    socket.OnClose = () =>
                        {
                            Console.WriteLine("Connection closed.");
                            sockets.Remove(socket);
                        };
                    socket.OnMessage = message =>
                        {
                            Console.WriteLine("Client says: " + message);
                            sockets.ToList().ForEach(s => s.Send(" client says:" + message));
                        };

                });

            string input = Console.ReadLine();
            while (input != "exit")
            {
                sockets.ToList().ForEach(s => s.Send(input));
                input = Console.ReadLine();
            }
        }
开发者ID:bvelji,项目名称:70-480_Practice,代码行数:32,代码来源:HelloServer.cs

示例10: Connec

        public Connec()
        {
            asdassd.Add("MenuGetir", Getir);

            Method_Call M = new Method_Call();
            //Type Ty = Type.GetType("InanYalcin_FleckSoket.Model.Site." + message, true);
            //var b = Ty;
            //var Deger = M.Method(Ty,message );

            FleckLog.Level = LogLevel.Debug;
            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://localhost:8181/consoleappsample");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    //var c = System.Activator.CreateInstance(Type.GetType("InanYalcin_FleckSoket.Model.Site." + message));
                    var c = asdassd[message]();
                    socket.Send(JsonConvert.SerializeObject(c, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
                    //allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
                };
            });
        }
开发者ID:rwx7540,项目名称:inanyalcin,代码行数:31,代码来源:Connec.cs

示例11: init

 public static void init()
 {
     FleckLog.Level = LogLevel.Debug;
     allSockets = new List<IWebSocketConnection>();
     server = new WebSocketServer("ws://localhost:1337");
     server.Start(socket =>
     {
         socket.OnOpen = () =>
         {
             Console.WriteLine("Open!");
             allSockets.Add(socket);
         };
         socket.OnClose = () =>
         {
             Console.WriteLine("Close!");
             allSockets.Remove(socket);
         };
         socket.OnMessage = message =>
         {
             Console.WriteLine(message);
             if (message == "SENDMEANIMAGE")
             {
                 Kinect.sendImage();
             }
         };
     });
 }
开发者ID:sydlawrence,项目名称:ubelly-kinect,代码行数:27,代码来源:Kinect.cs

示例12: Main

        static void Main()
        {
            FleckLog.Level = LogLevel.Debug;
            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://0.0.0.0:8181");

            server.Start(socket =>
                {
                    socket.OnOpen = () =>
                        {
                            Console.WriteLine("Open!");
                            allSockets.Add(socket);
                        };
                    socket.OnClose = () =>
                        {
                            Console.WriteLine("Close!");
                            allSockets.Remove(socket);
                        };
                    socket.OnMessage = message =>
                        {
                            Console.WriteLine(message);

                            // process the message
                            dynamic gameState = gameServer.MessageBroker.ProcessMessage(message);
                            string serializedState = _serializer.Serialize(gameState);
                            //allSockets.ToList().ForEach(s => s.Send("Echo: "));
                        };
                });

            var input = Console.ReadLine();
            while (input != "exit")
            {
                input = Console.ReadLine();
            }
        }
开发者ID:mrtown,项目名称:engine,代码行数:35,代码来源:WebsocketHandler.cs

示例13: StartServer

        public void StartServer()
        {
            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://localhost:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    //Console.WriteLine("Open!");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    //Console.WriteLine("Close!");
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    var date = DateTime.Now.ToShortTimeString();
                    //SaveMessage(socket.ConnectionInfo.Id, message);
                    //Console.WriteLine(message);
                    allSockets.ToList().ForEach(s => s.Send(date + ": " + message));
                };
            });

            //server.Close();

            //ServiceHost host = new ServiceHost(typeof(MyService));
        }
开发者ID:sonpv90,项目名称:storage-andreish,代码行数:30,代码来源:ChatService.svc.cs

示例14: Main

        static void Main(string[] args)
        {
            var webSocketServer = new WebSocketServer("ws://127.0.0.1:8081");
            var sockets = new List<IWebSocketConnection>();

            webSocketServer.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    sockets.Add(socket);
                };

                socket.OnMessage = mensagem =>
                {
                    foreach (var s in sockets)
                    {
                        s.Send(mensagem);
                    }
                };

                socket.OnClose = () =>
                {
                    sockets.Remove(socket);
                };
            });

            Console.ReadKey();
        }
开发者ID:branux,项目名称:20480-Turma-KaSolution-Noturno-08-Set-15,代码行数:28,代码来源:Program.cs

示例15: InitializeSockets

        public void InitializeSockets()
        {
            _sockets = new List<IWebSocketConnection>();

            var server = new WebSocketServer("ws://localhost:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    _sockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    _sockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();

                    dynamic obj = js.Deserialize<object>(message);
                    dynamic listaComandos = obj["Palabras"];
                    Audio.añadirComandos(listaComandos);
                };
            });
        }
开发者ID:CesarGamarra,项目名称:ServidorKinect-PizarraVirtual,代码行数:26,代码来源:Conexion.cs


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