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


C# Server.MapConnection方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.AutoFlush = true;

            string url = "http://localhost:8081/";
            var server = new Server(url);
            server.Configuration.DisconnectTimeout = TimeSpan.Zero;

            // Map connections
            server.MapConnection<MyConnection>("/echo")
                  .MapConnection<Raw>("/raw")
                  .MapHubs();

            server.Start();

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

            while (true)
            {
                ConsoleKeyInfo ki = Console.ReadKey(true);
                if (ki.Key == ConsoleKey.X)
                {
                    break;
                }
            }
        }
开发者ID:nairit,项目名称:SignalR,代码行数:27,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.AutoFlush = true;

            string url = "http://*:8081/";
            var server = new Server(url);
            
            // Map /echo to the persistent connection
            server.MapConnection<MyConnection>("/echo");

            server.Start();

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

            Console.ReadKey();
        }
开发者ID:daodao10,项目名称:SignalR.WebApi,代码行数:17,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.AutoFlush = true;
            FleckLog.Level = LogLevel.Debug;

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

            // Main web server
            var server = new Server("http://localhost:8081/");

            // Helper file server
            var fileServer = new FileServer("http://localhost:8081/public/", @"..\..\www");

            // Hijack the negotiation request
            server.OnProcessRequest = hostContext =>
            {
                // The server supports websockets
                hostContext.Items[HostConstants.SupportsWebSockets] = true;

                // In negotiation, we tell the client the url of the web socket server for this connection
                hostContext.Items[HostConstants.WebSocketServerUrl] = wss.Location + hostContext.Request.Url.LocalPath.Replace("/negotiate", "");
            };

            wss.Start(socket =>
            {
                PersistentConnection connection;
                if (server.TryGetConnection(socket.ConnectionInfo.Path, out connection))
                {
                    // Initalize the connection
                    connection.Initialize(server.DependencyResolver);

                    var req = new FleckWebSocketRequest(socket.ConnectionInfo, wss.IsSecure);
                    var hostContext = new HostContext(req, null, null);

                    // Stack the socket in the items collection so the transport can use it
                    hostContext.Items["Fleck.IWebSocketConnection"] = socket;

                    try
                    {
                        connection.ProcessRequestAsync(hostContext).ContinueWith(task =>
                        {
                            Console.WriteLine(task.Exception.GetBaseException());
                        },
                        TaskContinuationOptions.OnlyOnFaulted);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    socket.Close();
                }
            });


            // HACK: Need to make it easier to plug this in cleaner
            var transportManager = (TransportManager)server.DependencyResolver.Resolve<ITransportManager>();

            // Register the websocket transport
            transportManager.Register("webSockets", context => GetFleckWebSocketTransport(server.DependencyResolver, context));

            server.MapConnection<Raw>("/raw");
            server.EnableHubs();

            server.Start();
            fileServer.Start();

            Process.Start("http://localhost:8081/public/raw/index.htm");

            Console.ReadKey();

            server.Stop();
            fileServer.Stop();
        }
开发者ID:randoom,项目名称:SignalR.Fleck,代码行数:78,代码来源:Program.cs


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