Esempio n. 1
0
        /// <summary>
        /// 以同步方式接收消息,并转换为UTF8编码格式的字符串,使用5000字节的默认缓冲区接收。
        /// </summary>
        /// <param name="socket">socket对象</param>
        public static string ReceiveMsg(Socket socket)
        {
            //定义接收缓冲区
            byte[] buffer = new byte[5000];
            //接收数据,获取接收到的字节数
            int receiveCount = socket.Receive(buffer);

            //定义临时缓冲区
            byte[] tempBuffer = new byte[receiveCount];
            //将接收到的数据写入临时缓冲区
            Buffer.BlockCopy(buffer, 0, tempBuffer, 0, receiveCount);
            //转换成字符串,并将其返回
            return(ConvertHelper.BytesToString(tempBuffer, Encoding.Default));
        }
Esempio n. 2
0
 public void ByteArrayTest()
 {
     byte[] testBytes = { 0, 1, 2, 3, 1, 2, 3, 1, 2, 1 };
     Assert.AreEqual(testBytes, ConvertHelper.HexStringToBytes(ConvertHelper.BytesToHexString(testBytes)));
     Assert.AreEqual(testBytes, ConvertHelper.StringToBytes(ConvertHelper.BytesToString(testBytes)));
 }
Esempio n. 3
0
        public void HexStringTest_UpperCaseFormat()
        {
            string hexTestString2 = "0F011FA2";

            Assert.True(string.Equals(hexTestString2, ConvertHelper.BytesToString(ConvertHelper.StringToBytes(hexTestString2)), StringComparison.CurrentCultureIgnoreCase));
        }
Esempio n. 4
0
        public void HexStringTest()
        {
            string hexTestString = "0f011fa2";

            Assert.AreEqual(hexTestString, ConvertHelper.BytesToString(ConvertHelper.StringToBytes(hexTestString)));
        }
Esempio n. 5
0
        public void PlainTextTest()
        {
            string testString = "Hello world. This is a testing string.";

            Assert.AreEqual(testString, ConvertHelper.BytesToString(ConvertHelper.StringToBytes(testString)));
        }
Esempio n. 6
0
 public string GetDecryptedString()
 {
     return(ConvertHelper.BytesToString(GetDecryptedBytes()));
 }