private void EndConnect(IAsyncResult result)
{
// find the connection.
Connection connection = result.AsyncState as Connection;
if (connection == null)
{
return;
}
try
{
// complete connection.
connection.OutgoingSocket.EndConnect(result);
// start read from client.
connection.ClientToServerBuffer = new byte[UInt16.MaxValue];
connection.IncomingSocket.BeginReceive(
connection.ClientToServerBuffer,
0,
connection.ClientToServerBuffer.Length,
SocketFlags.None,
OnReadFromClient,
connection);
// start read from server.
connection.ServerToClientBuffer = new byte[UInt16.MaxValue];
connection.OutgoingSocket.BeginReceive(
connection.ServerToClientBuffer,
0,
connection.ServerToClientBuffer.Length,
SocketFlags.None,
OnReadFromServer,
connection);
}
catch (Exception e)
{
Utils.Trace(e, "Unexpected error connecting to server.");
Close(connection);
}
}