private void Connect() {
// initialize the client
IPAddress ipToBindTo = IPAddress.Parse( ConfigKey.IP.GetString() );
IPEndPoint localEndPoint = new IPEndPoint( ipToBindTo, 0 );
client = new TcpClient( localEndPoint ) {
NoDelay = true,
ReceiveTimeout = Timeout,
SendTimeout = Timeout
};
client.Client.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1 );
// connect
client.Connect( hostName, port );
// prepare to read/write
reader = new StreamReader( client.GetStream() );
writer = new StreamWriter( client.GetStream() );
isConnected = true;
}