in my simple udp server finder script when i select client it makes unity crash and i can't find why;
the comment code is what makes the crash; when i uncomment the while loop in StartClient function it crashes so at first i though it was the while loop that made it crash so i commented it and wrote it again in the update function so when i say that clientstarted is true in startclient() the update function will run the code but that makes it crash also, so i can't realy guess what makes it crash (when i mean crash i mean in windows make the editor not respond and eventually close itself and on android just close the app).
import System.Net.Sockets;
private var udp_server:UdpClient;
private var udp_client:UdpClient;
private var udp_port:int = 18000;
private var udp_broadcast_ip:IPAddress = IPAddress.Parse ("224.0.0.224");
private var udp_received_message:String;
private var udp_endpoint:IPEndPoint;
private var selected:boolean = false;
private var clientStarted:boolean = false;
function StartServer(){
udp_server = new UdpClient(udp_port, AddressFamily.InterNetwork);
udp_server.JoinMulticastGroup(udp_broadcast_ip);
udp_endpoint = new IPEndPoint(udp_broadcast_ip, udp_port);
InvokeRepeating("StartBroadcastUDP", 0.0,0.3);
}
function StartClient(){
udp_client = new UdpClient();
udp_endpoint = new IPEndPoint(IPAddress.Any, udp_port);
udp_client.Client.Bind(udp_endpoint);
udp_client.JoinMulticastGroup(udp_broadcast_ip);
/*
while(true){
yield;
var udp_received_message_byte:byte[] = udp_client.Receive(udp_endpoint);
udp_received_message = Encoding.Unicode.GetString(udp_received_message_byte);
print("Received Message: " + udp_received_message);
}*/
clientStarted = true;
}
function StartBroadcastUDP(){
var udp_broadcast_message = Encoding.Unicode.GetBytes("GAME SERVER");
if(udp_broadcast_message != ""){
udp_server.Send(udp_broadcast_message, udp_broadcast_message.Length);
}
}
function OnGUI(){
if(!selected){
if(GUI.Button(Rect(0, 0, 100, 100), "Server")){
StartServer();
selected = true;
}else if(GUI.Button(Rect(100, 0, 100, 100), "Client")){
StartClient();
selected = true;
}
}
}
function Update(){
/*
if(clientStarted){
var udp_received_message_byte:byte[] = udp_client.Receive(udp_endpoint);
udp_received_message = Encoding.Unicode.GetString(udp_received_message_byte);
print("Received Message: " + udp_received_message);
}*/
}
and if it helps here is the log file http://pastebin.com/JZ1kY62a
↧