Пример #1
0
        public void Start()
        {
            List <Fleck.IWebSocketConnection> sockets = new List <Fleck.IWebSocketConnection>();
            var 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();
            }
        }
Пример #2
0
        public void Start(string connectionStr)
        {
            server = new Fleck.WebSocketServer(connectionStr);

            server.Start(socket =>
                {
                    socket.OnOpen = () => { AsyncTaskQueue.Instance.AddAsyncAction( () => { OnOpen(socket); } ); };
                    socket.OnClose = () => { AsyncTaskQueue.Instance.AddAsyncAction(() => { OnClose(socket); }); };
                    socket.OnMessage = (message) => { AsyncTaskQueue.Instance.AddAsyncAction(() => { OnMessage(socket, message); }); };
                });
        }
Пример #3
0
        //readonly string Email = "*****@*****.**";
        //readonly string Password = "******";
        //readonly string BotToken = "MTkyNjI4NzY5ODMwMjA3NDg5.CkLnBQ.ZvmlN4E2koYhcOOKX5z2wYOrmcE";

        static void Main(string[] args)
        {
            var websocketServet = new Fleck.WebSocketServer("ws://0.0.0.0");

            websocketServet.Start(socket =>
            {
                socket.OnOpen  = () => Console.WriteLine("WebSocket Open");
                socket.OnClose = () => Console.WriteLine("WebSocket Closed");
            });
            KWRBot bot = new KWRBot();

            bot.Login();
            Console.ReadKey();
            bot.Exit();
        }
Пример #4
0
        private void StartWebSocketChatServer()
        {
            var _connections = new List<Fleck.IWebSocketConnection>();
            _server = new Fleck.WebSocketServer("ws://*****:*****@"logs\websocketerror.txt");
                            var data = DateTime.Now + Environment.NewLine + ex.ToString() + Environment.NewLine;
                            lock (_websocketErrorLogLock)
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(path));
                                File.AppendAllText(path, data);
                            }
                        };
                    socket.OnOpen =
                        () =>
                        {
                            _connections.Add(socket);
                        };
                    socket.OnClose =
                        () =>
                        {
                            _connections.Add(socket);
                        };
                    socket.OnMessage =
                        (msg) =>
                        {
                            foreach (var s in _connections)
                            {
                                s.Send(msg);
                            }
                        };
                });
        }