Esempio n. 1
0
        /// <summary>
        /// 构建连接
        /// </summary>
        public NSocket CreateConnect(SocketType socketType, string server, int port, Action connectSucess = null)
        {
            var connention = new NSocket(new IPEndPoint(IPAddress.Parse(server), port), 0);

            connention.MaxReConnectNums = 0;
            connention.OnConnectFailed  = OnConnectFailed;
            if (connectSucess != null)
            {
                connention.OnConnectSuccessful = connectSucess;
            }
            else
            {
                connention.OnConnectSuccessful = OnConnectSuccessful;
            }
            connention.OnDisconnect    = delegate { Timer.Instance.AddTimer(0, 1, 0, () => { OnDisconnect(connention); }); };
            connention.OnReceiveBuff   = OnReceiveBuff;
            connention.OnRquestTimeOut = OnSendBuffTimeOut;
            ConnentionDic.Add(socketType, connention);
            connention.StartTcpConnection();
            return(connention);
        }