Пример #1
0
        public WebThread(WebServerHandler handler, TcpSocket socket)
        {
            String req = new String();

            byte[] ch = new byte[1];
            while (true)
            {
                int read = socket.Read(ch, 0, 1);
                if (read == 1)
                {
                    req.Append((char)ch[0]);
                }
                if (req.EndsWith("\r\n\r\n"))
                {
                    String[]   lns     = req.Split("\r\n");
                    String[]   pts     = lns[0].Split(' '); //method url HTTP/version
                    String     method  = pts[0];
                    String     url     = pts[1];
                    WebRequest request = new WebRequest(new Url(url));
                    request.SetMethod(WebRequest.GetMethod(method));
                    WebReply  reply = new WebServerReply();
                    ByteArray post  = socket.ReadAll();
                    request.SetData(post);
                    handler.Process(request, reply);
                    String headerarray = reply.GetHeaders();
                    byte[] headerdata  = headerarray.ToByteArray();
                    socket.Write(headerdata, 0, headerdata.Length);
                    ByteArray outarraydata = reply.GetData();
                    byte[]    outdata      = outarraydata.ToArray();
                    socket.Write(outdata, 0, outdata.Length);
                    req.Length = 0;
                }
            }
        }
Пример #2
0
        private void OnTcpConnect(TcpServer server)
        {
            TcpSocket socket = server.Accept();
            WebThread thread = new WebThread(handler, socket);

            thread.Start();
        }