Here is the code :
private String sendString(string message)
{
try
{
//if (message != "")
//{
//Sending data to client--->
byte[] data = Encoding.UTF8.GetBytes(message);
int re = client.Send(data, data.Length, remoteEndPoint);
//Receiving data from client--->
byte[] recv = client.Receive(ref remoteEndPoint);
//Debug.Log("Received from " + remoteEndPoint.Address.ToString());
String result = System.Text.Encoding.UTF8.GetString(recv);
//Debug.Log (result + " " + remoteEndPoint.Address.ToString());
return result;
//}
}
catch (Exception err)
{
print(err.ToString());
return "false";
}
}
This works fine as long as the app is connected to the server. But as soon as it is disconnected from the server, the game freezes.
Can someone please help with this?
EDIT: I have found out that client.Receive causes the problem. Because as soon as I remove the receive part, it does not freeze even after the client is disconnected.