void Start () {
// Start resolving IPs
Tools.ResolveIPs();
// We don't want mobile devices to dim their screen and go to sleep while the app is running
Screen.sleepTimeout = SleepTimeout.NeverSleep;
// Make it possible to use UDP using a small random range of port
TNManager.StartUDP(Random.Range(10000,10030));
//if the random port gets locked by other users port than randomize once more
while(TNManager.canUseUDP){
TNManager.StartUDP(Random.Range(10000,10030));
}
//UdpProtocol.defaultNetworkInterface = Tools.localAddress;
tnobj = GetComponent<TNObject>();
ServerName = SystemInfo.deviceName;
directConnectionIp = Tools.localAddress;
ServerIpStr = directConnectionIp.ToString();
}
.
.
.
public IEnumerator LanSendServerInfoUDP()
{
while(true){
//start broadcasting the server info from udp through lan broadcast
yield return new WaitForSeconds
(1
.5f
); message = ServerName + '@' + ServerIpStr;
for(int i = 10000;i<= 10030;i++){
tnobj.BroadcastToLAN(i,"ReceiveServerInfo",message);
}
yield return null;
}
}
.
.
.
[RFC]
public void ReceiveServerInfo(string broadcastServerInfo){
string[] responseMessage
= broadcastServerInfo
.Split(new char[] { '@' },
System.StringSplitOptions.RemoveEmptyEntries); IpToConnect = responseMessage[1] ;
stringToEditRcv = "message received " + responseMessage[1] ;
}