IEnumerator SetupServer(ChildServerInformation info) { int Port = PlayerPrefs.GetInt("SubscribePort"); MapID = info.MapID; ChildServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipAdr = Dns.GetHostEntry(PlayerPrefs.GetString("SubscribeAddress")).AddressList[0]; IPEndPoint ipEp = new IPEndPoint(ipAdr, Port); ChildServerSocket.Connect(ipEp); MessageSetupServer setup = new MessageSetupServer(); WWW w = new WWW(@"http://icanhazip.com/"); yield return(w); Debug.Log("Complete!"); info.Address = w.text.Replace("\n", ""); setup.information = info; Debug.Log(JsonUtility.ToJson(info)); byte[] b = ServerManager.EncodeMessage(JsonUtility.ToJson(setup)); ChildServerSocket.Send(b); yield return(null); }
public void OnJoinServerButtonClick() { NetworkInterface.Instance.DeActiveAllInterface(); try{ NetworkInterface.Instance.JoiningGame(information.Address, information.Port); }catch (Exception ex) { NetworkInterface.Instance.ActiveAllInterface(); information = null; IndexerServerOutputer.text = "<color=red>加入游戏失败!错误信息为:</color>" + "\n" + ex.ToString(); } }
public void EstablishingGame(ChildServerInformation info) { ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipAdr = IPAddress.Parse(info.Address); IPEndPoint ipEp = new IPEndPoint(ipAdr, info.Port); ServerSocket.Bind(ipEp); //Listen ServerSocket.Listen(50); Debug.Log("Success!"); StartCoroutine(SetupServer(info)); StartCoroutine(ReciveMessage()); }
void StartGame() { ChildServerInformation info = new ChildServerInformation(ServerName, ServerDescription, ClientManager.Version, address, port, ChosedMap); if (IsServer) { server.gameObject.SetActive(true); server.EstablishingGame(info); client.gameObject.SetActive(true); client.Connection(address, port); } else { client.gameObject.SetActive(true); client.Connection(address, port); } }
public void Setup(ChildServerInformation info) { information = info; text.text = info.Name; }
public void OnChildServerButtonClick(ChildServerInformation info) { IndexerServerOutputer.text = info.Name + "\n" + info.Description + "\n" + info.Version + "\n" + info.Address + ":" + info.Port; information = info; }