Esempio n. 1
0
 /// <summary>
 /// 连接Tcp服务器
 /// </summary>
 /// <param name="host"></param>
 /// <param name="port"></param>
 public void ConnectTcpServer(string host, int port, string bgphost, int bgpport, SocketName _socketName, ConnectDelegate callBack, bool bgpConnect)
 {
     for (int i = 0; i < TcpPros.Length; i++)
     {
         if (TcpPros[i] == null)
         {
             TcpPros[i]            = new ProtoInfo();
             TcpPros[i].socketName = _socketName;
             TcpPros[i].host       = host;
             TcpPros[i].port       = port;
             TcpPros[i].bdphost    = bgphost;
             TcpPros[i].bdpport    = bgpport;
             TcpPros[i].outSetWork = true;
             TcpPros[i].pro        = gameObject.AddComponent <ProtoLayer>();
         }
         if (TcpPros[i].socketName == _socketName)
         {
             TcpPros[i].host       = host;
             TcpPros[i].port       = port;
             TcpPros[i].bdphost    = bgphost;
             TcpPros[i].bdpport    = bgpport;
             TcpPros[i].outSetWork = true;
             if (bgpConnect)
             {
                 TcpPros[i].pro.StartTcpSocket(bgphost, bgpport, _socketName, callBack);
             }
             else
             {
                 TcpPros[i].pro.StartTcpSocket(host, port, _socketName, callBack);
             }
             break;
         }
     }
 }
Esempio n. 2
0
 public float GetPingTime(SocketName _socketName = SocketName.MainSocket)
 {
     for (int i = 0; i < TcpPros.Length; i++)
     {
         ProtoInfo proto = TcpPros[i];
         if (proto != null && proto.socketName == _socketName)
         {
             proto.pro.HeartBeatInterval = 1;
             return(proto.pro.PingTime);
         }
     }
     return(0);
 }
Esempio n. 3
0
    public static void InitParse(string strSrc)
    {
        Regex regex = new Regex(@"class\s+(?<className>\w+)\s+\[key=(?<keyName>\w+),source=[""](?<fileSrc>\w+.[a-z]+)[""]\](?<fields>[\s\S\w\W\d\D\\[\]\n]+)");
        Match match = regex.Match(strSrc);

        if (match.Success)
        {
            Debug.Log("FindMath: class name  " + match.Groups["className"].Value + " ID: " + match.Groups["keyName"].Value +
                      " FileSrc: " + match.Groups["fileSrc"].Value);
            Debug.Log(" Fields:\n " + match.Groups["fields"].Value);

            ProtoInfo info = new ProtoInfo();
            info.ClassName = match.Groups["className"].Value;
            info.KeyName   = match.Groups["keyName"].Value;
            info.SrcFile   = match.Groups["fileSrc"].Value;
            string fieldsStr = match.Groups["fields"].Value;


            Match m = Regex.Match(fieldsStr, @"(?<filedType>[\w\d]+)\s+(?<filedName>[\w\d]+);?\s+\[option=[""](?<tableField>\w+)[""]\]\s?(?<comment>//(.*?)\r?\n)?");

            //匹配注释的原理:(?<comment>//(.*?)\r?\n)?尤其要注意括号后面的?表示()里的匹配内容是可选的
            while (m.Success)
            {
                ProtoInfo.ProtoFiledInfo protoFiledInfo = new ProtoInfo.ProtoFiledInfo();
                protoFiledInfo.CommentStr     = m.Groups["comment"].Value;
                protoFiledInfo.FieldName      = m.Groups["filedName"].Value;
                protoFiledInfo.FiledType      = m.Groups["filedType"].Value;
                protoFiledInfo.TableFieldName = m.Groups["tableField"].Value;
                info.FieldList.Add(protoFiledInfo);
                Debug.Log("Found  " + protoFiledInfo.FiledType + " " + protoFiledInfo.FieldName + "  " + protoFiledInfo.CommentStr + " " + protoFiledInfo.TableFieldName);
                m = m.NextMatch();
            }
        }
        else
        {
            Debug.Log("Mathch fail :\n" + strSrc);
        }
    }