public bool Connect(string hostname, Int32 port)
{
this.hostname = hostname;
this.port = port;
if (tcpClient == null)
{
tcpClient = new TcpClient();
tcpClient.NoDelay = true;
}
/* Allow 5 seconds for connection attempt, otherwise throw Exception */
IAsyncResult result = tcpClient.BeginConnect(this.hostname, this.port, null, null);
bool success = result.AsyncWaitHandle.WaitOne(5000, true);
if (!tcpClient.Connected)
{
throw new TransportException("Error connecting socket");
}
this.StartThread();
dispatcher.OnConnect();
return tcpClient.Connected;
}