1
What good is the code below the Manualresetevent connectDone? If I use it, when running the main thread hangs, as I am using this code within the Unity3d(game engine) it hangs the entire process and this cannot occur.
What is the real need to use it? What is the point?
//static ManualResetEvent connectDone = new ManualResetEvent(false);
static ManualResetEvent sendDone = new ManualResetEvent(false);
static ManualResetEvent receiveDone = new ManualResetEvent(false);
public static void Connect()
{
string ServerIP = "127.0.0.1";
int ServerPort = 5902;
try
{
EndPoint remoteEP = new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), clientSocket);
//connectDone.WaitOne();
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
}
private static void ConnectCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
Debug.Log("Socket connected to " + client.RemoteEndPoint.ToString());
// Signal that the connection has been made.
//connectDone.Set();
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
}