123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace LYFZ.Network
- {
-
-
-
- public class TCP_ProtocolHandler
- {
- private string partialProtocol;
- public TCP_ProtocolHandler()
- {
- partialProtocol = "";
- }
- public string[] GetProtocol(string input)
- {
- return GetProtocol(input, null);
- }
-
-
-
-
-
-
-
- private string[] GetProtocol(string input, List<string> outputList)
- {
- if (outputList == null)
- outputList = new List<string>();
- if (String.IsNullOrEmpty(input))
- return outputList.ToArray();
- if (!String.IsNullOrEmpty(partialProtocol))
- input = partialProtocol + input;
- string pattern = "(^<lyfz_protocol>.*?</lyfz_protocol>)";
- HPSocketCS.Extended.SystemFileLogs.WriteLogs("匹配协议:" + input);
-
- if (Regex.IsMatch(input, pattern))
- {
-
- string match = Regex.Match(input, pattern).Groups[0].Value;
- outputList.Add(match);
- partialProtocol = "";
-
- input = input.Substring(match.Length);
-
- GetProtocol(input, outputList);
- }
- else
- {
-
-
- partialProtocol = input;
- }
- return outputList.ToArray();
- }
-
-
-
-
-
- public string GetProtocolInfo(string input)
- {
- string pattern = "(^<lyfz_protocol>.*?</lyfz_protocol>)";
-
-
- if (Regex.IsMatch(input, pattern))
- {
-
-
- string match = Regex.Match(input, pattern).Groups[0].Value;
- return match;
- }
- else
- {
-
-
- return "";
- }
- }
- }
- }
|