public static ServerSearchEngineRequest Parse(string xml, ISearchHost host)
        {
            var      request = new ServerSearchEngineRequest(host);
            Document doc     = new Document();

            doc.LoadXml(xml);
            foreach (Node node in doc.Root.Nodes)
            {
                if (node.NodeName.ToLower() == "method")
                {
                    var methodName = node.Name.ToLower();
                    if (!String.IsNullOrEmpty(methodName))
                    {
                        request.MethodName = methodName;
                        foreach (Node prm in node.Nodes)
                        {
                            if (prm.NodeName.ToLower() == "parameter")
                            {
                                request.Parameters.Add(prm.Name, prm.NodeValue);
                            }
                        }
                    }
                    break;
                }
            }

            return(request);
        }
        private void handleRequest(object clientParam)
        {
            var client = clientParam as TcpClient;
            ServerSearchEngineRequest req = null;
            string inputXml = null;

            try {
                NetworkStream clientStream = client.GetStream();

                inputXml = Toolkit.ReadAllStreamText(clientStream, "</req>");

                req = ServerSearchEngineRequest.Parse(inputXml, _searcher);

                // determine which method they're wanting to call and call it
                // NOTE: Execute() NEVER throws exceptions, just puts them into its .Exception property
                req.Execute();
            } catch (Exception ex) {
                if (req == null)
                {
                    req           = new ServerSearchEngineRequest(_searcher);
                    req.Exception = ex;
                }
                Logger.LogText("Error when handling request in basic TCP server: " + ex.Message, ex);
            } finally {
                // stream result back to them
                try {
                    var outputBytes  = UTF8Encoding.UTF8.GetBytes(req.ToXml());
                    var outputStream = client.GetStream();
                    outputStream.Write(outputBytes, 0, outputBytes.Length);
                    outputStream.Flush();
                } finally {
                    // clean up
                    client.Close();
                }
            }
        }