public void SearchingServer() { SearchingAgentSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); string Address = IndexerServerAddressInputField.text; int Port = int.Parse(IndexerServerPortInputField.text); IPAddress ipAd = null; try{ ipAd = Dns.GetHostEntry(Address).AddressList[0]; }catch (SocketException ex) { Debug.Log(ex.ErrorCode); } Debug.Log(ipAd.ToString()); IPEndPoint ipEp = new IPEndPoint(ipAd, Port); SearchingAgentSocket.Connect(ipEp); PlayerPrefs.SetString("SubscribeAddress", Address); PlayerPrefs.SetInt("SubscribePort", Port); IndexerServerOutputer.text = "连接索引器成功!"; MessageSetupClient setup = new MessageSetupClient(); setup.Version = ClientManager.Version; MessageGetServerIPAddress request = new MessageGetServerIPAddress(); byte[] b = ServerManager.EncodeMessage(JsonUtility.ToJson(setup)); SearchingAgentSocket.Send(b); Invoke("Refresh", 0.5f); }
public void Refresh() { MessageGetServerIPAddress request = new MessageGetServerIPAddress(); byte[] b = ServerManager.EncodeMessage(JsonUtility.ToJson(request)); IndexerServerOutputer.text = "正在发送..."; SearchingAgentSocket.Send(b); StartCoroutine(OnRefresh()); }