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


C# Byte.ToHex方法代码示例

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


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

示例1: ShowMethod

        private static void ShowMethod(IntPtr mt)
        {
            XTrace.WriteLine("ShowMethod: {0}", mt.ToString("x"));
            var buf = new Byte[8];
            Marshal.Copy(mt, buf, 0, buf.Length);
            //XTrace.WriteLine(buf.ToHex("-"));

            var ip = new IntPtr((Int64)buf.ToUInt64());
            XTrace.WriteLine("{0}", ip.ToString("x"));

            if (ip.ToInt64() <= 0x1000000 || ip.ToInt64() > 0x800000000000L) return;

            buf = new Byte[32];
            Marshal.Copy(ip, buf, 0, buf.Length);
            XTrace.WriteLine(buf.ToHex("-"));
        }
开发者ID:tommybiteme,项目名称:X,代码行数:16,代码来源:ApiHook.cs

示例2: Send

        /// <summary>发送数据</summary>
        /// <remarks>
        /// 目标地址由<seealso cref="SessionBase.Remote"/>决定
        /// </remarks>
        /// <param name="buffer">缓冲区</param>
        /// <param name="offset">偏移</param>
        /// <param name="count">数量</param>
        /// <returns>是否成功</returns>
        public override Boolean Send(Byte[] buffer, Int32 offset = 0, Int32 count = -1)
        {
            if (Disposed) throw new ObjectDisposedException(GetType().Name);

            if (!Open()) return false;

            if (count < 0) count = buffer.Length - offset;

            if (StatSend != null) StatSend.Increment(count);

            try
            {
                var sp = Client;
                lock (sp)
                {
                    if (Client.Connected)
                    {
                        if (Log.Enable && LogSend) WriteLog("Send [{0}]: {1}", count, buffer.ToHex(0, Math.Min(count, 32)));

                        sp.Send(buffer, offset, count, SocketFlags.None);
                    }
                    else
                    {
                        if (Log.Enable && LogSend) WriteLog("Send {2} [{0}]: {1}", count, buffer.ToHex(0, Math.Min(count, 32)), Remote.EndPoint);

                        sp.SendTo(buffer, offset, count, SocketFlags.None, Remote.EndPoint);
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                if (!ex.IsDisposed())
                {
                    OnError("Send", ex);

                    // 发送异常可能是连接出了问题,UDP不需要关闭
                    //Close();

                    if (ThrowException) throw;
                }
                return false;
            }
        }
开发者ID:tommybiteme,项目名称:X,代码行数:53,代码来源:UdpServer.cs

示例3: SendAsync_

        internal Boolean SendAsync_(Byte[] buffer, IPEndPoint remote)
        {
            if (!Open()) return false;

            var count = buffer.Length;

            if (StatSend != null) StatSend.Increment(count);
            if (Log.Enable && LogSend) WriteLog("SendAsync [{0}]: {1}", count, buffer.ToHex(0, Math.Min(count, 32)));

            LastTime = DateTime.Now;

            // 估算完成时间,执行过长时提示
            using (var tc = new TimeCost("{0}.SendAsync".F(GetType().Name), 500))
            {
                tc.Log = Log;

                // 同时只允许一个异步发送,其它发送放入队列

                // 考虑到超长数据包,拆分为多个包
                var max = 1472;
                if (buffer.Length <= max)
                {
                    var qi = new QueueItem();
                    qi.Buffer = buffer;
                    qi.Remote = remote;

                    _SendQueue.Enqueue(qi);
                }
                else
                {
                    var ms = new MemoryStream(buffer);
                    while (true)
                    {
                        var remain = (Int32)(ms.Length - ms.Position);
                        if (remain <= 0) break;

                        var len = Math.Min(remain, max);

                        var qi = new QueueItem();
                        qi.Buffer = ms.ReadBytes(len);
                        qi.Remote = remote;

                        _SendQueue.Enqueue(qi);
                    }
                }

                CheckSendQueue(false);
            }

            return true;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:51,代码来源:SessionBase.cs

示例4: Send

        /// <summary>发送数据</summary>
        /// <remarks>
        /// 目标地址由<seealso cref="SessionBase.Remote"/>决定
        /// </remarks>
        /// <param name="buffer">缓冲区</param>
        /// <param name="offset">偏移</param>
        /// <param name="count">数量</param>
        /// <returns>是否成功</returns>
        public override Boolean Send(Byte[] buffer, Int32 offset = 0, Int32 count = -1)
        {
            if (!Open()) return false;

            if (count < 0) count = buffer.Length - offset;

            if (StatSend != null) StatSend.Increment(count);
            if (Log != null && Log.Enable && LogSend) WriteLog("Send [{0}]: {1}", count, buffer.ToHex(0, Math.Min(count, 32)));

            try
            {
                // 修改发送缓冲区
                if (Client.SendBufferSize < count) Client.SendBufferSize = count;

                if (count == 0)
                    Client.Send(new Byte[0]);
                else
                    Client.Send(buffer, offset, count, SocketFlags.None);
            }
            catch (Exception ex)
            {
                if (!ex.IsDisposed())
                {
                    OnError("Send", ex);

                    // 发送异常可能是连接出了问题,需要关闭
                    Close("发送出错");
                    Reconnect();

                    if (ThrowException) throw;
                }

                return false;
            }

            LastTime = DateTime.Now;

            return true;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:47,代码来源:TcpSession.cs


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