本文整理汇总了C#中WebSocket.FireError方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocket.FireError方法的具体用法?C# WebSocket.FireError怎么用?C# WebSocket.FireError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocket
的用法示例。
在下文中一共展示了WebSocket.FireError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
{
var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
commandInfo.Text.ParseMimeHeader(dict);
string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);
if (!session.NotSpecifiedVersion)
{
if (string.IsNullOrEmpty(websocketVersion))
session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
else
session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
session.CloseWithoutHandshake();
return;
}
if (string.IsNullOrEmpty(websocketVersion))
{
session.FireError(new Exception("unknown server protocol version"));
session.CloseWithoutHandshake();
return;
}
var versions = websocketVersion.Split(',');
versions = versions.Where((x) => x.Trim().Length > 0).ToArray();
var versionValues = new int[versions.Length];
for (var i = 0; i < versions.Length; i++)
{
try
{
int value = int.Parse(versions[i]);
versionValues[i] = value;
}
catch (FormatException)
{
session.FireError(new Exception("invalid websocket version"));
session.CloseWithoutHandshake();
return;
}
}
if (!session.GetAvailableProcessor(versionValues))
{
session.FireError(new Exception("unknown server protocol version"));
session.CloseWithoutHandshake();
return;
}
session.ProtocolProcessor.SendHandshake(session);
}
示例2: ExecuteCommand
public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
{
var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
var verbLine = string.Empty;
commandInfo.Text.ParseMimeHeader(dict, out verbLine);
string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);
if (!session.NotSpecifiedVersion)
{
if (string.IsNullOrEmpty(websocketVersion))
session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
else
session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
session.CloseWithoutHandshake();
return;
}
if (string.IsNullOrEmpty(websocketVersion))
{
session.FireError(new Exception("unknown server protocol version"));
session.CloseWithoutHandshake();
return;
}
var versions = websocketVersion.Split(m_ValueSeparator, StringSplitOptions.RemoveEmptyEntries);
var versionValues = new int[versions.Length];
for (var i = 0; i < versions.Length; i++)
{
int value;
if (!int.TryParse(versions[i], out value))
{
session.FireError(new Exception("invalid websocket version"));
session.CloseWithoutHandshake();
return;
}
versionValues[i] = value;
}
if (!session.GetAvailableProcessor(versionValues))
{
session.FireError(new Exception("unknown server protocol version"));
session.CloseWithoutHandshake();
return;
}
session.ProtocolProcessor.SendHandshake(session);
}
示例3: ExecuteCommand
public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
{
string description;
if (!session.ProtocolProcessor.VerifyHandshake(session, commandInfo, out description))
{
session.FireError(new Exception(description));
session.Close(session.ProtocolProcessor.CloseStatusCode.ProtocolError, description);
return;
}
session.OnHandshaked();
}
示例4: ExecuteCommand
public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
{
//Close handshake was sent from client side, now got a handshake response
if (session.State == WebSocketState.Closing)
{
//Not NormalClosure
if (commandInfo.CloseStatusCode != session.ProtocolProcessor.CloseStatusCode.NormalClosure &&
(commandInfo.CloseStatusCode > 0 || !string.IsNullOrEmpty(commandInfo.Text)))
{
session.FireError(new Exception(string.Format("{0}: {1}", commandInfo.CloseStatusCode, commandInfo.Text)));
}
session.CloseWithouHandshake();
return;
}
//Got server side closing handshake request, send response now
var statusCode = commandInfo.CloseStatusCode;
if (statusCode <= 0)
statusCode = session.ProtocolProcessor.CloseStatusCode.NoStatusCode;
session.Close(statusCode, commandInfo.Text);
}