protected override void _Load() { for (int i = 0; i < m_csv.GetRows(); i++) { DnsCsvData data = new DnsCsvData(); data.www = m_csv.GetData(i, (int)eDnsCsv.www); data.ip = m_csv.GetData(i, (int)eDnsCsv.ip); data.bz = m_csv.GetData(i, (int)eDnsCsv.bz); m_dicData.Add(data.www, data); } }
public void Conn(string ip, int port, Action coonCb) { Debug.Log("new start Connect"); Stop(); m_netState = NetState.Connecting; m_recvHeartBeatTime = 0; m_ip = ip; m_port = port; m_connectedCb = coonCb; IPAddress ipAddres = null; if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) { Debug.Log("Connect wifi"); IPAddress[] address = null; try { address = Dns.GetHostAddresses(m_ip); } catch (Exception e) { Debug.Log("Dns解析异常, ip:" + m_ip + " port:" + m_port + " " + e); m_netState = NetState.ConnFail; return; } if (address[0].AddressFamily == AddressFamily.InterNetworkV6) { Debug.Log("Connect InterNetworkV6"); m_socketClient = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); } else { Debug.Log("Connect InterNetworkV4"); m_socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } ipAddres = address[0]; } else { Debug.Log("Connect 4g, 源 ip:" + m_ip); if (m_ip.Contains(".com")) { DnsCsv csv = CsvManager.Inst.GetCsv <DnsCsv>((int)eAllCSV.eAC_Dns); DnsCsvData data = csv.GetData(m_ip); m_ip = data.ip; Debug.Log("Connect 4g, 最终 ip:" + m_ip); } m_socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress.TryParse(m_ip, out ipAddres); } if (ipAddres == null) { Debug.Log("ipAddres is null, ip:" + m_ip + " port:" + m_port); m_netState = NetState.ConnFail; return; } m_nSend = new NetAsynSend(m_socketClient); m_nRecv = new NetAsynRecv(m_socketClient); IPEndPoint serverIP = new IPEndPoint(ipAddres, m_port); m_socketClient.BeginConnect(serverIP, ConnSucc, null); }