// (c) 2004 Electronic Arts Inc.
//

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace EA.GameTalkRouter
{
	/// <summary>
	/// Summary description for Connection.
	/// </summary>
	public class TcpConnect : System.Net.Sockets.TcpClient
	{
		/// <summary>
		/// Get the socket connection.
		/// </summary>
		internal Socket ClientSocket
		{
			get { return this.Client; }
		}

		/// <summary>
		/// Constructor.
		/// </summary>
		public TcpConnect() :
			base()
		{
			// Specify the client to be removed right after close is called
			this.LingerState = new LingerOption(false, 0);

			// Send right away without delays
			this.NoDelay = true;
		}

		/// <summary>
		/// Connect to the host on the specified port
		/// </summary>
		/// <param name="host">The host to connect to.</param>
		/// <param name="port">The port to connect to.</param>
		/// <returns>The result of the connection.</returns>
		public new bool Connect(string host, int port)
		{
			bool result = false;
			try
			{
				// Connect to target platform
				base.Connect(host, port);
				result = true;
			}
			catch (Exception e)
			{
				Trace.WriteLine("ErrorConnecting: " + e.Message);
			}

			return result;
		}
	}
}
