本文整理汇总了C#中IWebSocketSession.SendRawData方法的典型用法代码示例。如果您正苦于以下问题:C# IWebSocketSession.SendRawData方法的具体用法?C# IWebSocketSession.SendRawData怎么用?C# IWebSocketSession.SendRawData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebSocketSession
的用法示例。
在下文中一共展示了IWebSocketSession.SendRawData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handshake
public override bool Handshake(IWebSocketSession session, WebSocketReceiveFilterBase previousFilter, out IReceiveFilter<IWebSocketFragment> dataFrameReader)
{
var secKey1 = session.Items.GetValue<string>(WebSocketConstant.SecWebSocketKey1, string.Empty);
var secKey2 = session.Items.GetValue<string>(WebSocketConstant.SecWebSocketKey2, string.Empty);
dataFrameReader = null;
if (string.IsNullOrEmpty(secKey1) && string.IsNullOrEmpty(secKey2) && NextProcessor != null)
{
return NextProcessor.Handshake(session, previousFilter, out dataFrameReader);
}
session.ProtocolProcessor = this;
if (!session.AppServer.ValidateHandshake(session, session.Items.GetValue<string>(WebSocketConstant.Origin, string.Empty)))
return false;
var secKey3 = session.Items.GetValue<byte[]>(WebSocketConstant.SecWebSocketKey3, m_ZeroKeyBytes);
var responseBuilder = new StringBuilder();
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseHeadLine00);
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseUpgradeLine);
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseConnectionLine);
if (!string.IsNullOrEmpty(session.Origin))
responseBuilder.AppendFormatWithCrCf(WebSocketConstant.ResponseOriginLine, session.Origin);
responseBuilder.AppendFormatWithCrCf(WebSocketConstant.ResponseLocationLine, session.UriScheme, session.Host, session.Path);
var subProtocol = session.GetAvailableSubProtocol(session.Items.GetValue<string>(WebSocketConstant.SecWebSocketProtocol, string.Empty));
if (!string.IsNullOrEmpty(subProtocol))
responseBuilder.AppendFormatWithCrCf(WebSocketConstant.ResponseProtocolLine, subProtocol);
responseBuilder.AppendWithCrCf();
byte[] data = Encoding.UTF8.GetBytes(responseBuilder.ToString());
session.SendRawData(data, 0, data.Length);
//Encrypt message
byte[] secret = GetResponseSecurityKey(secKey1, secKey2, secKey3);
session.SendRawData(secret, 0, secret.Length);
dataFrameReader = new WebSocketDataReceiveFilter(previousFilter);
return true;
}
示例2: Handshake
public override bool Handshake(IWebSocketSession session, WebSocketRequestFilterBase previousFilter, out IRequestFilter<IWebSocketFragment> dataFrameReader)
{
if (!VersionTag.Equals(session.SecWebSocketVersion) && NextProcessor != null)
{
return NextProcessor.Handshake(session, previousFilter, out dataFrameReader);
}
dataFrameReader = null;
session.ProtocolProcessor = this;
var secWebSocketKey = session.Items.GetValue<string>(WebSocketConstant.SecWebSocketKey, string.Empty);
if (string.IsNullOrEmpty(secWebSocketKey))
{
return false;
}
var responseBuilder = new StringBuilder();
string secKeyAccept = string.Empty;
try
{
secKeyAccept = Convert.ToBase64String(SHA1.Create().ComputeHash(Encoding.ASCII.GetBytes(secWebSocketKey + m_Magic)));
}
catch (Exception)
{
return false;
}
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseHeadLine10);
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseUpgradeLine);
responseBuilder.AppendWithCrCf(WebSocketConstant.ResponseConnectionLine);
responseBuilder.AppendFormatWithCrCf(WebSocketConstant.ResponseAcceptLine, secKeyAccept);
var subProtocol = session.GetAvailableSubProtocol(session.Items.GetValue<string>(WebSocketConstant.SecWebSocketProtocol, string.Empty));
if (!string.IsNullOrEmpty(subProtocol))
responseBuilder.AppendFormatWithCrCf(WebSocketConstant.ResponseProtocolLine, subProtocol);
responseBuilder.AppendWithCrCf();
byte[] data = Encoding.UTF8.GetBytes(responseBuilder.ToString());
session.SendRawData(data, 0, data.Length);
dataFrameReader = new WebSocketDataFrameRequestFilter();
return true;
}
示例3: SendPackage
private void SendPackage(IWebSocketSession session, int opCode, byte[] data, int offset, int length)
{
byte[] fragment;
if (length < 126)
{
fragment = new byte[2 + length];
fragment[1] = (byte)length;
}
else if (length < 65536)
{
fragment = new byte[4 + length];
fragment[1] = (byte)126;
fragment[2] = (byte)(length / 256);
fragment[3] = (byte)(length % 256);
}
else
{
fragment = new byte[10 + length];
fragment[1] = (byte)127;
int left = length;
int unit = 256;
for (int i = 9; i > 1; i--)
{
fragment[i] = (byte)(left % unit);
left = left / unit;
if (left == 0)
break;
}
}
fragment[0] = (byte)(opCode | 0x80);
if (length > 0)
{
Buffer.BlockCopy(data, offset, fragment, fragment.Length - length, length);
}
session.SendRawData(fragment, 0, fragment.Length);
}
示例4: SendCloseHandshake
public override void SendCloseHandshake(IWebSocketSession session, int statusCode, string closeReason)
{
session.SendRawData(WebSocketConstant.ClosingHandshake, 0, WebSocketConstant.ClosingHandshake.Length);
}
示例5: SendMessage
public override void SendMessage(IWebSocketSession session, string message)
{
var packageData = GetPackageData(message);
session.SendRawData(packageData.Array, packageData.Offset, packageData.Count);
}
示例6: Handshake
public bool Handshake(IWebSocketSession session, WebSocketReceiveFilterBase previousReader, out IReceiveFilter<IWebSocketFragment> dataFrameReader)
{
dataFrameReader = null;
session.SendRawData(m_SwitchResponse, 0, m_SwitchResponse.Length);
return true;
}
示例7: SendMessage
public override void SendMessage(IWebSocketSession session, string message)
{
var maxByteCount = Encoding.UTF8.GetMaxByteCount(message.Length) + 2;
var sendBuffer = new byte[maxByteCount];
sendBuffer[0] = WebSocketConstant.StartByte;
int bytesCount = Encoding.UTF8.GetBytes(message, 0, message.Length, sendBuffer, 1);
sendBuffer[1 + bytesCount] = WebSocketConstant.EndByte;
session.SendRawData(sendBuffer, 0, bytesCount + 2);
}
示例8: SendPackage
private void SendPackage(IWebSocketSession session, int opCode, byte[] data, int offset, int length)
{
var fragment = GetPackageData(opCode, data, offset, length);
session.SendRawData(fragment, 0, fragment.Length);
}