本文整理汇总了C#中WebSocketSharp.WebSocket.Ping方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.Ping方法的具体用法?C# WebSocket.Ping怎么用?C# WebSocket.Ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocketSharp.WebSocket
的用法示例。
在下文中一共展示了WebSocket.Ping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClient
private static WebSocket GetClient(ServantConfiguration configuration)
{
var url = "ws://" + configuration.ServantIoUrl + "/Client?installationGuid=" + configuration.InstallationGuid + "&organizationGuid=" + configuration.ServantIoKey + "&servername=" + System.Environment.MachineName;
using (var ws = new WebSocket(url))
{
var serializer = new JavaScriptSerializer();
var pingTimer = new System.Timers.Timer(2000);
pingTimer.Elapsed += (sender, args) =>
{
ws.Ping();
};
pingTimer.Enabled = false;
ws.OnMessage += (sender, e) =>
{
var request = serializer.Deserialize<CommandRequest>(e.Data);
switch (request.Command)
{
case CommandRequestType.Unauthorized:
IsStopped = true;
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(DateTime.Now.ToLongTimeString() + ": Servant.io key was not recognized.");
Console.ResetColor();
ws.Close();
break;
case CommandRequestType.GetSites:
var sites = SiteManager.GetSites();
var result = serializer.Serialize(sites);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid)
{
Guid = request.Guid,
Message = result,
Success = true
}));
break;
case CommandRequestType.UpdateSite:
var site = serializer.Deserialize<Site>(request.JsonObject);
var originalSite = SiteManager.GetSiteByName(request.Value);
if (originalSite == null)
{
ws.Send("not_found");
return;
}
originalSite.ApplicationPool = site.ApplicationPool;
originalSite.Name = site.Name;
originalSite.SiteState = site.SiteState;
originalSite.Bindings = site.Bindings;
originalSite.LogFileDirectory = site.LogFileDirectory;
originalSite.SitePath = site.SitePath;
originalSite.Bindings = site.Bindings;
SiteManager.UpdateSite(originalSite);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Message = "ok", Success = true}));
break;
case CommandRequestType.GetApplicationPools:
var appPools = SiteManager.GetApplicationPools();
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) {Message = serializer.Serialize(appPools), Success = true}));
break;
case CommandRequestType.GetCertificates:
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) {Message = serializer.Serialize(SiteManager.GetCertificates()), Success = true}));
break;
case CommandRequestType.StartSite:
var startSite = SiteManager.GetSiteByName(request.Value);
var startResult = SiteManager.StartSite(startSite);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Success = startResult == SiteStartResult.Started, Message = startResult.ToString() }));
break;
case CommandRequestType.StopSite:
var stopSite = SiteManager.GetSiteByName(request.Value);
SiteManager.StopSite(stopSite);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Success = true }));
break;
case CommandRequestType.RecycleApplicationPool:
var recycleSite = SiteManager.GetSiteByName(request.Value);
SiteManager.RecycleApplicationPoolBySite(recycleSite.IisId);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Message = "ok", Success = true }));
break;
case CommandRequestType.RestartSite:
var restartSite = SiteManager.GetSiteByName(request.Value);
SiteManager.RestartSite(restartSite.IisId);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Message = "ok", Success = true }));
break;
case CommandRequestType.DeleteSite:
var deleteSite = SiteManager.GetSiteByName(request.Value);
SiteManager.DeleteSite(deleteSite.IisId);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Message = "ok", Success = true }));
break;
case CommandRequestType.CreateSite:
var createSite = serializer.Deserialize<Site>(request.JsonObject);
var id = SiteManager.CreateSite(createSite);
ws.Send(serializer.Serialize(new CommandResponse(request.Guid) { Message = id.ToString(), Success = true }));
break;
}
};
//.........这里部分代码省略.........