本文整理汇总了C#中WebSocketFrame.AsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocketFrame.AsBytes方法的具体用法?C# WebSocketFrame.AsBytes怎么用?C# WebSocketFrame.AsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebSocketFrame
的用法示例。
在下文中一共展示了WebSocketFrame.AsBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: streamData
private void streamData(object sender, ElapsedEventArgs e)
{
streamTimer.Interval = streamRate;
DataSources dataSources = new DataSources();
if (toRun.Count + subscriptions.Count > 0)
{
try
{
List<string> entries = new List<string>();
APIEntry entry = null;
lock (subscriptionLock)
{
dataSources.vessel = kspAPI.getVessel();
//Only parse the paused argument if the active vessel is null
if (dataSources.vessel != null)
{
toRun.UnionWith(subscriptions);
foreach (string s in toRun)
{
DataSources dataSourcesClone = dataSources.Clone();
string trimedQuotes = s.Trim();
string refArg = trimedQuotes;
kspAPI.parseParams(ref refArg, ref dataSourcesClone);
kspAPI.process(refArg, out entry);
if (entry != null)
{
entry.formatter.setVarName(trimedQuotes);
entries.Add(entry.formatter.format(entry.function(dataSourcesClone)));
}
}
toRun.Clear();
if (entry != null)
{
WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes(entry.formatter.pack(entries)));
byte[] bFrame = frame.AsBytes();
dataRates.addDownLinkPoint(System.DateTime.Now, bFrame.Length * UpLinkDownLinkRate.BITS_PER_BYTE);
clientConnection.Send(bFrame);
}
}
else
{
sendNullMessage();
}
}
}
catch(NullReferenceException)
{
PluginLogger.debug("Swallowing null reference exception, potentially due to async game state change.");
sendNullMessage();
}
catch (Exception ex)
{
PluginLogger.debug("Closing socket due to potential client disconnect:" + ex.GetType().ToString());
close();
}
}
else
{
sendNullMessage();
}
}
示例2: OpCodeText
public void OpCodeText(object sender, FrameEventArgs e)
{
WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes("Echo: " + e.frame.PayloadAsUTF8()));
e.clientConnection.Send(frame.AsBytes());
}
示例3: sendNullMessage
protected void sendNullMessage()
{
WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes("{}"));
clientConnection.Send(frame.AsBytes());
}