当前位置: 首页>>代码示例>>C#>>正文


C# WebSocketFrame.AsBytes方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:hwirth,项目名称:Telemachus,代码行数:71,代码来源:KSPWebSocketService.cs

示例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());
 }
开发者ID:Technicalfool,项目名称:Telemachus,代码行数:5,代码来源:MinimalWebSocketServerTest.cs

示例3: sendNullMessage

 protected void sendNullMessage()
 {
     WebSocketFrame frame = new WebSocketFrame(ASCIIEncoding.UTF8.GetBytes("{}"));
     clientConnection.Send(frame.AsBytes());
 }
开发者ID:hwirth,项目名称:Telemachus,代码行数:5,代码来源:KSPWebSocketService.cs


注:本文中的WebSocketFrame.AsBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。