本文整理汇总了C#中WebSocketServer.AddWebSocketService方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer.AddWebSocketService方法的具体用法?C# WebSocketServer.AddWebSocketService怎么用?C# WebSocketServer.AddWebSocketService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocketServer
的用法示例。
在下文中一共展示了WebSocketServer.AddWebSocketService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string [] args)
{
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");
#if DEBUG
wssv.Log.Level = LogLevel.TRACE;
#endif
//var cert = ConfigurationManager.AppSettings ["ServerCertFile"];
//var password = ConfigurationManager.AppSettings ["CertFilePassword"];
//wssv.Certificate = new X509Certificate2 (cert, password);
//wssv.KeepClean = false;
wssv.AddWebSocketService<Echo> ("/Echo");
wssv.AddWebSocketService<Chat> ("/Chat");
//wssv.AddWebSocketService<Chat> ("/Chat", () => new Chat ("Anon#"));
//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);
}
Console.WriteLine ("\nPress Enter key to stop server...");
Console.ReadLine ();
wssv.Stop ();
}
示例2: Main
public static void Main(string [] args)
{
/* Single service server
var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649");
//var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649/Echo");
//var wssv = new WebSocketServiceHost<Echo> ("ws://localhost:4649/エコー");
//var wssv = new WebSocketServiceHost<Echo> (4649);
//var wssv = new WebSocketServiceHost<Echo> (4649, "/Echo");
//var wssv = new WebSocketServiceHost<Echo> (4649, "/エコー");
//var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649");
//var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649/Chat");
//var wssv = new WebSocketServiceHost<Chat> ("ws://localhost:4649/チャット");
//var wssv = new WebSocketServiceHost<Chat> (4649);
//var wssv = new WebSocketServiceHost<Chat> (4649, "/Chat");
//var wssv = new WebSocketServiceHost<Chat> (4649, "/チャット");
#if DEBUG
wssv.Log.Level = LogLevel.TRACE;
#endif
//wssv.KeepClean = false;
wssv.Start ();
Console.WriteLine (
"WebSocket Service Host (url: {0})\n listening on address: {1} port: {2}\n",
wssv.Uri, wssv.Address, wssv.Port);
*/
/* Multi services server */
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");
#if DEBUG
wssv.Log.Level = LogLevel.TRACE;
#endif
//var file = ConfigurationManager.AppSettings ["ServerCertFile"];
//var password = ConfigurationManager.AppSettings ["CertFilePassword"];
//wssv.Certificate = new X509Certificate2 (file, password);
//wssv.KeepClean = false;
wssv.AddWebSocketService<Echo> ("/Echo");
wssv.AddWebSocketService<Chat> ("/Chat");
//wssv.AddWebSocketService<Echo> ("/エコー");
//wssv.AddWebSocketService<Chat> ("/チャット");
wssv.Start ();
Console.WriteLine (
"WebSocket Server listening on port: {0} service path:", wssv.Port);
foreach (var path in wssv.ServicePaths)
Console.WriteLine (" {0}", path);
Console.WriteLine ();
Console.WriteLine ("Press enter key to stop server...");
Console.ReadLine ();
wssv.Stop ();
}
示例3: Main
static void Main(string[] args)
{
C.WriteLine("Loading resources...");
Resources.Load();
C.WriteLine("Starting server...");
var wss = new WebSocketServer(11882);
wss.AddWebSocketService<RunPatternService>("/run");
wss.AddWebSocketService<ResourcesService>("/resources");
wss.Start();
C.WriteLine("#GServer running. Press a key to stop.");
Console.ReadKey(true);
C.WriteLine("Stopping...");
wss.Stop();
C.WriteLine("#YStopped. Have a nice day.");
}
示例4: WebSockServer
public WebSockServer(int port)
{
TaskQueue.QeueAsync(_threadName, () => {
Port = port;
Commands = new Dictionary<string, CMD>();
ConnectedUsers = new Dictionary<string, WebSockUser>();
_server = new WebSocketServer(port);
_server.Log.Output = Log;
_server.AddWebSocketService("/echo", () => new Echo() { IgnoreExtensions = true });
_server.AddWebSocketService("/server", () => new WebSockUser(this) { IgnoreExtensions = true });
_server.Start();
_watch = new Stopwatch();
_watch.Start();
});
}
示例5: MainWindow
public MainWindow()
{
InitializeComponent();
wsServer = new WebSocketServer(IPAddress.Parse("127.0.0.1"), 1234);
wsServer.AddWebSocketService<Echo>("/");
wsServer.Start();
}
示例6: Start
public void Start()
{
try
{
var socketServer = new WebSocketServer(this._port, this._isSSL);
socketServer.AddWebSocketService<WSClientBehaviour>(this._path);
if (this._isSSL)
{
//configure SSL for websocket server (just to test this feature!)
string basedir = AppDomain.CurrentDomain.BaseDirectory;
string certPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(basedir, @"..\serverCertificate.pfx"));
if (!System.IO.File.Exists(certPath))
throw new Exception("I did not found the SSL certificate for the websocket server");
var passwd = "password";
socketServer.SslConfiguration.ServerCertificate = new X509Certificate2(certPath, passwd);
}
socketServer.Log.Output = (logData, msg) =>
{
if (logData.Level == LogLevel.Error || logData.Level == LogLevel.Fatal)
this.OnError(new Exception(logData.Message));
};
this._socketServer = socketServer;
socketServer.Start();
MessageService.Start(this);
}
catch (Exception ex)
{
this.OnError(ex);
}
}
示例7: Awake
public void Awake()
{
// Just in case cancel all old invokes related to this instance
CancelInvoke ();
// Do a full sync
//FullSync ();
// Add all vessels to the vessel list
foreach (Vessel vessel in FlightGlobals.Vessels) {
if (!all_vessels.Contains (vessel)) {
all_vessels.Add (vessel);
}
}
InvokeRepeating ("UpdateClients",1.0F,1.0F);
if (wssv == null) {
Debug.Log ("Establishing websocket");
wssv = new WebSocketServer (12321); //TODO: Add possibility to configure IP
wssv.AddWebSocketService<MissionControlService> ("/mcs", () => new MissionControlService (this));
wssv.Start ();
Debug.Log ("Established websocket!");
}
}
示例8: Initialize
private static void Initialize () {
wsServer = new WebSocketServer(
WebConsoleDefinitions.SERVE_PROTOCOL + WebConsoleDefinitions.SERVE_ADDRESS + ":" + WebConsoleDefinitions.SERVE_PORT
);
wsServer.AddWebSocketService<WSServerInstance>("/");
wsServer.Start();
}
示例9: Setup
public void Setup()
{
_symbols = new List<Symbol>()
{
Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
Symbol.Create("AIG", SecurityType.Equity, Market.USA)
};
Config.Set("live-data-url", "ws://127.0.0.1");
Config.Set("live-data-port", "8080");
_mockServerBehavior = new MockServerBehavior();
_dataQueueHandler = new ApiDataQueueHandler();
var liveDataUri = new Uri(Config.Get("live-data-url"));
var uriBuilder = new UriBuilder(liveDataUri);
uriBuilder.Port = Config.GetInt("live-data-port");
Task.Run(() =>
{
_mockServer = new WebSocketServer(uriBuilder.ToString());
_mockServer.AddWebSocketService("/", () => _mockServerBehavior);
Log.Trace("ApiDataQueueHandlerTests.Setup(): Starting the mock server.");
_mockServer.Start();
while (true)
{
Thread.Sleep(1000);
}
});
}
示例10: Start
public void Start(string address, int port, string path)
{
IPAddress ipaddr = new IPAddress(address.Split('.').Select(a => (byte)a.to_i()).ToArray());
WebSocketServer wss = new WebSocketServer(ipaddr, port, this);
wss.AddWebSocketService<ServerReceiver>(path);
wss.Start();
}
示例11: Main
public static void Main(string[] args)
{
var wssv = new WebSocketServer("ws://127.0.0.1");
wssv.AddWebSocketService<CatServer>("/cat");
wssv.Start();
Console.WriteLine("Server started");
Console.ReadKey(true);
wssv.Stop();
}
示例12: Main
static void Main(string[] args)
{
var wssv = new WebSocketServer("ws://localhost:8181/");
wssv.AddWebSocketService<Laputa>("/");
Console.WriteLine("Listening...");
wssv.Start();
Console.ReadKey(true);
wssv.Stop();
}
示例13: Main
public static void Main(string[] args)
{
/* Single service server
//var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649");
var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649/Echo");
//var wssv = new WebSocketServiceHost<Echo>("ws://localhost:4649/エコー");
//var wssv = new WebSocketServiceHost<Echo>(4649);
//var wssv = new WebSocketServiceHost<Echo>(4649, "/Echo");
//var wssv = new WebSocketServiceHost<Echo>(4649, "/エコー");
//var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649");
//var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649/Chat");
//var wssv = new WebSocketServiceHost<Chat>("ws://localhost:4649/チャット");
//var wssv = new WebSocketServiceHost<Chat>(4649);
//var wssv = new WebSocketServiceHost<Chat>(4649, "/Chat");
//var wssv = new WebSocketServiceHost<Chat>(4649, "/チャット");
//wssv.Sweeping = false; // Stop the sweep inactive session timer.
wssv.Start();
Console.WriteLine(
"WebSocket Service Host (url: {0})\n listening on address: {1} port: {2}\n",
wssv.Uri, wssv.Address, wssv.Port);
*/
// Multi services server
var wssv = new WebSocketServer(4649);
//var wssv = new WebSocketServer("ws://localhost:4649");
//wssv.Sweeping = false; // Stop the sweep inactive session timer.
wssv.AddWebSocketService<Echo>("/Echo");
wssv.AddWebSocketService<Chat>("/Chat");
//wssv.AddWebSocketService<Echo>("/エコー");
//wssv.AddWebSocketService<Chat>("/チャット");
wssv.Start();
Console.WriteLine(
"WebSocket Server listening on port: {0} service path:", wssv.Port);
foreach (var path in wssv.ServicePaths)
Console.WriteLine(" {0}", path);
Console.WriteLine();
Console.WriteLine("Press any key to stop server...");
Console.ReadLine();
wssv.Stop();
}
示例14: ServerMonitor
ServerMonitor()
{
maxSize = new Vector2 (360, 380);
minSize = maxSize;
_log = new StringBuilder (64);
_logStyle = new GUIStyle ();
_logStyle.fontStyle = FontStyle.Normal;
//_logStyle.normal.background = ;
_sync = new object ();
_updated = false;
_server = new WebSocketServer (4649);
_server.Log.Level = LogLevel.TRACE;
_server.Log.SetOutput (OutputLog);
_server.AddWebSocketService<Echo> ("/Echo");
_server.AddWebSocketService<Chat> ("/Chat");
_server.Start ();
}
示例15: Start
public static void Start(string url, int port)
{
try
{
dipsServer = new WebSocketServer(port);
dipsServer.AddWebSocketService<DiPSServer>("/" + url);
dipsServer.Start();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}