private void ConnectCallback(IAsyncResult result)
{
try
{
this.client.EndConnect(result);
}
catch (Exception ex)
{
this.IsConnected = false;
if (this.connectionFailed != null)
{
this.connectionFailed(this, new ConnectionFailedEventArgs(ex));
return;
}
}
NetworkStream stream = this.client.GetStream();
byte[] buffer = new byte[this.client.ReceiveBufferSize];
this.IsConnected = true;
if (this.connectionEstablished != null)
{
this.connectionEstablished(this, EventArgs.Empty);
}
stream.BeginRead(buffer, 0, buffer.Length, this.ReceiveCallback, buffer);
}