コード例 #1
0
ファイル: Program.cs プロジェクト: dralee/LeeDevSp
        static void ChannelActive(BufferConnection bc)
        {
            HelloRequest req = new HelloRequest.Builder()
                               .SetUser("JackieLee")
                               .SetText("Hello proxy")
                               .Build();

            msgXp.cmdId = CMD_ID_HELLO_VALUE;
            msgXp.body  = req.ToByteArray();

            byte[] toSendBuf = msgXp.encode();

            bc.Send(toSendBuf);
        }
コード例 #2
0
        //重写基类方法,当链接上服务器后,马上发送Hello World消息到服务端
        public override void ChannelActive(IChannelHandlerContext context)
        {
            HelloRequest req = new HelloRequest.Builder()
                               .SetUser("JackieLee")
                               .SetText("Hello proxy")
                               .Build();

            msgXp.cmdId = CMD_ID_HELLO_VALUE;
            msgXp.body  = req.ToByteArray();

            byte[]      toSendBuf = msgXp.encode();
            IByteBuffer encoded   = context.Allocator.Buffer(toSendBuf.Length);

            encoded.WriteBytes(toSendBuf);
            context.WriteAndFlushAsync(encoded);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: dralee/LeeDevSp
        static void Main01(string[] args)
        {
            HelloRequest req = new HelloRequest.Builder()
                               .SetUser("JackieLee")
                               .SetText("Hello")
                               .Build();

            byte[] buffer = req.ToByteArray();

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:8080/");
            ByteArrayContent content = new ByteArrayContent(buffer);

            content.Headers.Add("Content-Type", "application/octet-stream");
            Stream        respStream = client.PostAsync("mars/hello", content).Result.Content.ReadAsStreamAsync().Result;
            HelloResponse resp       = HelloResponse.ParseFrom(respStream);
        }