Connect() публичный Метод

连接开始
public Connect ( int nSocketID, string ip, int portnumber, INetworkMsgHandler listener ) : bool
nSocketID int
ip string 服务器IP地址
portnumber int 端口信息
listener INetworkMsgHandler
Результат bool
Пример #1
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 创建连接
        /// </summary>
        /// <param name="id"></param>
        /// <param name="host"></param>
        /// <param name="port"></param>
        /// <param name="listener"></param>
        public void Connect(int id, string host, int port, INetworkMsgHandler listener)
        {
            SetReadyToConnectSID(id);

            if (ENUM_SOCKET_STATE.eSocket_Connected == m_currentConnectState)
            {
                if (id == m_currentConnectedSID)
                {
                    Debug.Log("NetTCPWork::Connect already connect the server ID = " + id);
                    return;
                }

                CNetTCPSocketConnect connect = new CNetTCPSocketConnect();
                bool success = connect.Connect(id, host, port, listener);
                if (success)
                {
                    SetCurrentServerID(id);
                    m_TCPConnects.Add(id, connect);
                }
            }
            else
            {
                Disconnect(id);

                CNetTCPSocketConnect connect = new CNetTCPSocketConnect();
                bool success = connect.Connect(id, host, port, listener);
                if (success)
                {
                    m_TCPConnects.Add(id, connect);
                }
            }
        }
Пример #2
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 创建连接
        /// </summary>
        /// <param name="id"></param>
        /// <param name="host"></param>
        /// <param name="port"></param>
        /// <param name="listener"></param>
        public void Connect(int id, string host, int port, INetworkMsgHandler listener)
        {
            SetReadyToConnectSID(id);

            if (ENUM_SOCKET_STATE.eSocket_Connected == m_currentConnectState)
            {
                if (id == m_currentConnectedSID)
                {
                    Debug.Log("NetTCPWork::Connect already connect the server ID = " + id);
                    return;
                }

                CNetTCPSocketConnect connect = new CNetTCPSocketConnect();
                bool success = connect.Connect(id,host, port, listener);
                if (success)
                {
                    SetCurrentServerID(id);
                    m_TCPConnects.Add(id, connect);
                }
            }
            else
            {
                Disconnect(id);

                CNetTCPSocketConnect connect = new CNetTCPSocketConnect();
                bool success = connect.Connect(id,host, port, listener);
                if (success)
                {
                    m_TCPConnects.Add(id, connect);
                }
            }
        }