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


C# BitStream.CopyTo方法代码示例

本文整理汇总了C#中NetGore.IO.BitStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.CopyTo方法的具体用法?C# BitStream.CopyTo怎么用?C# BitStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetGore.IO.BitStream的用法示例。


在下文中一共展示了BitStream.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

        /// <summary>
        /// Attempts to connects to the server.
        /// </summary>
        /// <param name="host">The server address.</param>
        /// <param name="port">The server port.</param>
        /// <param name="approvalMessage">The initial message to send to the server when making the connection. This can
        /// be utilized by the server to provide additional information for determining whether or not to accept the connection.
        /// Or, can be null to send nothing.</param>
        /// <returns>
        /// True if the connection attempt was successfully started. Does not mean that the connection was established, but
        /// just that it can be attempted. Will return false if a connection is already established or being established.
        /// </returns>
        public bool Connect(string host, int port, BitStream approvalMessage = null)
        {
            if (_local.ConnectionsCount > 0)
                return false;

            NetConnection conn;

            if (approvalMessage != null && approvalMessage.LengthBits > 0)
            {
                // Connect with approval message
                var netOutMsg = SocketHelper.GetNetOutgoingMessage(_local, approvalMessage.LengthBytes);
                approvalMessage.CopyTo(netOutMsg);

                conn = _local.Connect(host, port, netOutMsg);
            }
            else
            {
                // Connect without approval message
                conn = _local.Connect(host, port);
            }

            // Check if connection successful
            if (conn == null)
            {
                Debug.Fail("conn is null. Why?");
                return false;
            }

            // Store the remote connection as an IPSocket
            _remote = IPSocket.Create(conn);

            return true;
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:45,代码来源:ClientSocketManager.cs

示例2: Send

        /// <summary>
        /// Sends data to the other end of the connection.
        /// </summary>
        /// <param name="data">Data to send.</param>
        /// <param name="deliveryMethod">The method to use to deliver the message. This determines how reliability, ordering,
        /// and sequencing will be handled.</param>
        /// <param name="sequenceChannel">The sequence channel to use to deliver the message. Only valid when
        /// <paramref name="deliveryMethod"/> is not equal to <see cref="NetDeliveryMethod.Unreliable"/> or
        /// <see cref="NetDeliveryMethod.ReliableUnordered"/>. Must also be a value greater than or equal to 0 and
        /// less than <see cref="NetConstants.NetChannelsPerDeliveryMethod"/>.</param>
        /// <returns>
        /// True if the <paramref name="data"/> was successfully enqueued for sending; otherwise false.
        /// </returns>
        /// <exception cref="NetException"><paramref name="deliveryMethod"/> equals <see cref="NetDeliveryMethod.Unreliable"/>
        /// or <see cref="NetDeliveryMethod.ReliableUnordered"/> and <paramref name="sequenceChannel"/> is non-zero.</exception>
        /// <exception cref="NetException"><paramref name="sequenceChannel"/> is less than 0 or greater than or equal to
        /// <see cref="NetConstants.NetChannelsPerDeliveryMethod"/>.</exception>
        /// <exception cref="NetException"><paramref name="deliveryMethod"/> equals <see cref="NetDeliveryMethod.Unknown"/>.</exception>
        public bool Send(BitStream data, NetDeliveryMethod deliveryMethod, int sequenceChannel = 0)
        {
            if (data == null || data.Length == 0)
                return false;

            var msg = SocketHelper.GetNetOutgoingMessage(_conn.Peer, data.LengthBytes);
            data.CopyTo(msg);

            var ret = _conn.SendMessage(msg, deliveryMethod, sequenceChannel);
            return ret == NetSendResult.Sent || ret == NetSendResult.Queued;
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:29,代码来源:IPSocket.cs


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