Mercurial > hg > ucis.core
diff Xml/Server.cs @ 0:3ab940a0c7a0
Initial commit
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 11 Sep 2012 16:28:53 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Xml/Server.cs Tue Sep 11 16:28:53 2012 +0200 @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Xml; +using UCIS.Net; + +namespace UCIS.Xml { + public class XmlServer : TCPServer.IModule { + public Dictionary<string, IModule> Modules = new Dictionary<string, IModule>(StringComparer.OrdinalIgnoreCase); + + public bool Accept(TCPStream Stream) { + XmlSocket XSocket = new XmlSocket(Stream); + Stream.ReadTimeout = 5000; + XmlDocument FirstMessage = XSocket.ReadDocument(); + if (FirstMessage == null) return true; + IModule module; + if (Modules.TryGetValue(FirstMessage.FirstChild.Name, out module)) { + module.Accept(XSocket, FirstMessage); + } else { + Console.WriteLine("XMLServer.Accept: Module not found: " + FirstMessage.FirstChild.Name); + } + return true; + } + + public interface IModule { + void Accept(XmlSocket Socket, XmlDocument FirstMessage); + } + } +}