void Socket_Connection_recieve(object Sender, Socktes.RecieveEventArgs e) { lock (recieveLocker) { string message = Encoding.UTF8.GetString(e.Data); //.Trim(); int endIndex = message.IndexOf("\0"); if (endIndex > 0) message = message.Remove(message.IndexOf("\0")); int iteration = 0; while (string.IsNullOrEmpty(message) == false) { iteration++; int firstIndexOf = message.IndexOf("<?xml"); if (firstIndexOf == -1) { partMessage += message; if (partMessage.EndsWith("</message>")) { messageProcessor.ProcessMessage(partMessage); partMessage = ""; } break; } else { partMessage += message.Substring(0, firstIndexOf); if (partMessage.EndsWith("</message>")) { messageProcessor.ProcessMessage(partMessage); partMessage = ""; } message = message.Remove(0, firstIndexOf); int lastIndexOf = message.IndexOf("</message>"); if (lastIndexOf == -1) { partMessage += message; break; } else { string fullMessage = message.Substring(0, lastIndexOf + "</message>".Length); messageProcessor.ProcessMessage(fullMessage); message = message.Remove(0, lastIndexOf + "</message>".Length); } } } } }
void Socket_Listen_accept(object Sender, Socktes.AcceptEventArgs e) { Socket_Connection.SocketHandle = e.ConnectedSocket; }