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


C# SocketBufferFake.SetBuffer方法代码示例

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


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

示例1: ParseHeader_SkipBody

        public void ParseHeader_SkipBody()
        {
            const string HttpPost = @"POST / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://localhost:8080/ajaxPost.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sv,en;q=0.8,en-US;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF

hello=world";
            string actual = "";
            var slice = new SocketBufferFake();
            var buffer = Encoding.UTF8.GetBytes(HttpPost);
            slice.SetBuffer(buffer, 0, buffer.Length);
            slice.BytesTransferred = buffer.Length;
            var parser = new HeaderParser();
            parser.HeaderParsed += (name, value) => actual = value;
            slice.Offset = parser.Parse(slice, 0);

            Assert.Equal("ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF", actual);
            Assert.Equal('h', (char)slice.Buffer[slice.Offset]);
        }
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:30,代码来源:HeaderParserTests.cs

示例2: ParsePost

        public void ParsePost()
        {
            const string HttpPost = @"POST / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
Content-Type: application/x-www-form-urlencoded; charset=UTF-32
Accept: */*
Referer: http://localhost:8080/ajaxPost.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sv,en;q=0.8,en-US;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF

hello=world";
            var buffer = new SocketBufferFake();
            buffer.SetBuffer(Encoding.ASCII.GetBytes(HttpPost), 0, HttpPost.Length);
            IHttpMessage message = null;

            var builder = new HttpMessageDecoder();
            builder.MessageReceived = o => message = (IHttpMessage) o;
            builder.ProcessReadBytes(buffer);


            message.Should().NotBeNull();
            message.ContentCharset.Should().Be(Encoding.UTF32);
            message.ContentLength.Should().Be(11);
            message.Body.Should().NotBeNull();
            message.Body.Position.Should().Be(0);
            message.Body.Length.Should().Be(11);
        }
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:34,代码来源:HttpMessageDecoderTests.cs

示例3: Parse

        public void Parse()
        {
            var buffer = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nSERVER: LOCALHOST\r\n\r\n");
            var slice = new SocketBufferFake();
            slice.SetBuffer(buffer, 0, buffer.Length);


            var parser = new HeaderParser();
            parser.HeaderParsed += (name, value) => Console.WriteLine(name + ": " + value);
            parser.Parse(slice, 0);
        }
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:11,代码来源:HeaderParserTests.cs

示例4: two_messages

        public void two_messages()
        {
            var buf = new Byte[] //two msgs with "Hello world" as content
            {
                96, 0, 1, 88, 0, 0, 0, 90, 83, 121, 115, 116, 101, 109, 46, 83, 116, 114, 105, 110, 103, 44, 32, 109, 115,
                99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44,
                32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108,
                105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101,
                48, 56, 57, 60, 115, 116, 114, 105, 110, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112,
                58, 47, 47, 115, 99, 104, 101, 109, 97, 115, 46, 109, 105, 99, 114, 111, 115, 111, 102, 116, 46, 99, 111,
                109, 47, 50, 48, 48, 51, 47, 49, 48, 47, 83, 101, 114, 105, 97, 108, 105, 122, 97, 116, 105, 111, 110,
                47, 34, 62, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 60, 47, 115, 116, 114, 105, 110, 103,
                62,
                96, 0, 1, 88, 0, 0, 0, 90, 83, 121, 115, 116, 101, 109, 46, 83, 116, 114, 105, 110, 103, 44, 32, 109, 115,
                99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44,
                32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108,
                105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101,
                48, 56, 57, 60, 115, 116, 114, 105, 110, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112,
                58, 47, 47, 115, 99, 104, 101, 109, 97, 115, 46, 109, 105, 99, 114, 111, 115, 111, 102, 116, 46, 99, 111,
                109, 47, 50, 48, 48, 51, 47, 49, 48, 47, 83, 101, 114, 105, 97, 108, 105, 122, 97, 116, 105, 111, 110,
                47, 34, 62, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 60, 47, 115, 116, 114, 105, 110, 103,
                62
            };
            var buffer = new SocketBufferFake();
            buffer.SetBuffer(buf, 0, buf.Length);
            buffer.BytesTransferred = buf.Length;
            var msgs = new List<string>();

            var sut = new MicroMessageDecoder(new DataContractMessageSerializer());
            sut.MessageReceived = o => msgs.Add((string)o);
            sut.ProcessReadBytes(buffer);

            msgs.Count.Should().Be(2);
            msgs[0].Should().StartWith("Hello world");
            msgs[1].Should().StartWith("Hello world");
        }
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:36,代码来源:MicroMessageDecoderTests.cs


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