コード例 #1
0
ファイル: Packet.cs プロジェクト: mahongbo86/SmartRoute
 public ArraySegment <byte> Encode(object data, IServer server, byte[] buffer)
 {
     using (XStream stream = new XStream(server.BufferPool))
     {
         IBinaryWriter writer = ServerFactory.CreateWriter(stream, server.Config.Encoding,
                                                           server.Config.LittleEndian);
         OnEncode(data, writer);
         stream.Position = 0;
         int count = (int)writer.Length;
         stream.Read(buffer, 0, count);
         return(new ArraySegment <byte>(buffer, 0, count));
     }
 }
コード例 #2
0
ファイル: Packet.cs プロジェクト: mahongbo86/SmartRoute
 public byte[] Encode(object data, IServer server)
 {
     byte[] result = null;
     using (XStream stream = new XStream(server.BufferPool))
     {
         IBinaryWriter writer = ServerFactory.CreateWriter(stream, server.Config.Encoding,
                                                           server.Config.LittleEndian);
         OnEncode(data, writer);
         stream.Position = 0;
         result          = new byte[stream.Length];
         stream.Read(result, 0, result.Length);
     }
     return(result);
 }
コード例 #3
0
ファイル: MyClass.cs プロジェクト: IDWMaster/OpenServer
        static void HandleonConnectionEstablished(XStream stream)
        {
            driver.onConnectionEstablished-= HandleonConnectionEstablished;
            int reqcount = currentRequest.headers.Count;
            BinaryWriter mwriter = new BinaryWriter(stream);
            mwriter.Write(reqcount);
            mwriter.Write("GET /"+currentURL.PathAndQuery+" HTTP/1.0");
            for(int i = 1;i<reqcount;i++) {
            mwriter.Write(currentRequest.headers[i]);
            }
            mwriter.Flush();
            byte[] buffer = new byte[16384];
            while(true) {
            try {
                int count = stream.Read(buffer,0,buffer.Length);

                    Console.WriteLine("DGRAM len: "+count.ToString());
                currentRequest.stream.Write(buffer,0,count);
                }catch(Exception er) {
                break;
                }
            }
            Console.WriteLine("Request complete");
            currentRequest.stream.Flush();
            mvent.Set();
        }