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


C# WebSocketServer.Start方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            string url = args.Length > 0 ? args[0] : "ws://localhost:8181";

            server = new WebSocketServer(url);

            server.Start(socket =>
            {
                socket.OnOpen = () => Open(socket);
                socket.OnClose = () => Close(socket);
                socket.OnMessage = message => Receive(socket, message);
            });

            Console.WriteLine("Type a message to send to the client (type 'exit' to close):");

            var input = Console.ReadLine();
            while (input != "exit")
            {
                foreach (IWebSocketConnection socket in allSockets)
                {
                    //standard socket raw send method
                    socket.Send(input);

                    //find our dynamic sockpuppet for this socket, and call a dynamic method
                    clientDynamicWindows[socket.ConnectionInfo.Id].document.write("called from a dynamic object method: " + input);

                    //find our strongly typed interface sockpuppet for this socket, and call a typed method (that matches a method for our chosen context on the client)\
                    clientWindows[socket.ConnectionInfo.Id].alert("called from an interface method: " + input);
                }

                input = Console.ReadLine();
            }
        }
开发者ID:developerdizzle,项目名称:SockPuppet,代码行数:33,代码来源:Program.cs

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

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

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

示例5: Main

        static void Main()
        {
            FleckLog.Level = LogLevel.Debug;
            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://localhost:8181");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("连接成功");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    Console.WriteLine("连接已关闭");
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    Console.WriteLine("客户端发来消息"+message);
                    //allSockets.ForEach(s => s.Send(message));
                };
            });

            var input = Console.ReadLine();
            while (input != "exit")
            {
                foreach (var socket in allSockets.ToList())
                {
                    socket.Send(input);
                }
                input = Console.ReadLine();
            }
        }
开发者ID:pear171902790,项目名称:Html5,代码行数:34,代码来源:Server.cs

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

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

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

示例9: StartWebSocketServer

    public bool StartWebSocketServer() {
      WSRConfig cfg = WSRConfig.GetInstance();

      int port = cfg.WebSocket;
      if (port < 0) { return false; }

      if (cfg.WSSmooth)  filter1 = new DepthFilteredSmoothing();
      if (cfg.WSAverage) filter2 = new DepthAveragedSmoothing();

      ImageFormat format = cfg.WSType == "png" ? ImageFormat.Png : ImageFormat.Jpeg;

      Sockets = new List<IWebSocketConnection>();
      Server = new WebSocketServer("ws://localhost:" + port);
      Server.Start(socket => {
        socket.OnOpen = () => {
          cfg.logInfo("WEBSCK", "Connected to: " + socket.ConnectionInfo.ClientIpAddress);
          lock (Sockets) { Sockets.Add(socket); }
        };
        socket.OnClose = () => {
          cfg.logInfo("WEBSCK", "Disconnected from: " + socket.ConnectionInfo.ClientIpAddress);
          lock (Sockets) { Sockets.Remove(socket); }
        };
        socket.OnMessage = message => {
          SendWebSocket(socket, GreenScreen(message), format);
        };
      });
      return true;
    }
开发者ID:jdelhommeau,项目名称:WSRMacro,代码行数:28,代码来源:WSRWebSocket.cs

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

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

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

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

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

示例15: Start

        public static void Start()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            FleckLog.Level = LogLevel.Debug;
            var allSockets = new List<IWebSocketConnection>();
            var server = new WebSocketServer("ws://0.0.0.0:8181");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Debug.WriteLine("Open!");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    Debug.WriteLine("Close!");
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    var jsonObj = serializer.Deserialize<MessageFormat>(message);
                    Debug.WriteLine("[username]: " + jsonObj.username);
                    Debug.WriteLine("[nickname]: " + jsonObj.nickname);
                    Debug.WriteLine("[content]: " + jsonObj.content);
                    Debug.WriteLine("");
                    string msg = String.Format("{0}: {1}", jsonObj.nickname, jsonObj.content);
                    allSockets.ToList().ForEach(s => s.Send(msg));
                };
            });
        }
开发者ID:monzy613,项目名称:fakebook-csharp-server,代码行数:31,代码来源:Server.cs


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