websocket-sharp/Example2/Program.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2012-08-04 14:51:31 +08:00
using System;
2013-07-19 16:29:58 +08:00
using System.Configuration;
using System.Security.Cryptography.X509Certificates;
2013-07-15 19:42:55 +08:00
using WebSocketSharp;
2012-08-06 13:34:39 +08:00
using WebSocketSharp.Server;
2012-08-04 14:51:31 +08:00
namespace Example2
{
public class Program
{
2013-07-19 16:29:58 +08:00
public static void Main (string [] args)
2012-08-04 14:51:31 +08:00
{
2013-07-19 16:29:58 +08:00
var wssv = new WebSocketServer (4649);
//var wssv = new WebSocketServer (4649, true);
//var wssv = new WebSocketServer ("ws://localhost:4649");
//var wssv = new WebSocketServer ("wss://localhost:4649");
2013-07-15 19:42:55 +08:00
#if DEBUG
wssv.Log.Level = LogLevel.TRACE;
#endif
//var cert = ConfigurationManager.AppSettings ["ServerCertFile"];
2013-07-19 16:29:58 +08:00
//var password = ConfigurationManager.AppSettings ["CertFilePassword"];
//wssv.Certificate = new X509Certificate2 (cert, password);
//wssv.KeepClean = false;
2013-07-19 16:29:58 +08:00
wssv.AddWebSocketService<Echo> ("/Echo");
wssv.AddWebSocketService<Chat> ("/Chat");
//wssv.AddWebSocketService<Chat> ("/Chat", () => new Chat ("Anon#"));
2013-07-19 16:29:58 +08:00
//wssv.AddWebSocketService<Echo> ("/エコー");
//wssv.AddWebSocketService<Chat> ("/チャット");
wssv.Start ();
if (wssv.IsListening)
{
Console.WriteLine (
"A WebSocket Server listening on port: {0} service paths:", wssv.Port);
foreach (var path in wssv.WebSocketServices.ServicePaths)
Console.WriteLine (" {0}", path);
}
2012-08-04 14:51:31 +08:00
Console.WriteLine ("\nPress Enter key to stop server...");
2013-07-19 16:29:58 +08:00
Console.ReadLine ();
2012-08-04 14:51:31 +08:00
2013-07-19 16:29:58 +08:00
wssv.Stop ();
2012-08-04 14:51:31 +08:00
}
}
}