本文整理汇总了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;
}
}
}
示例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();
}
示例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();
}