public cTcpSocketServer(cTcpSocket tcpSocket, int iListenPort)
        {
            TcpSocket  = tcpSocket;
            ListenPort = iListenPort;


            if (iListenPort < 1 || iListenPort > 65535)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Portnumber is invalid");
            }
            else
            {
                try
                {
                    listener = new TcpListener(IPAddress.Any, ListenPort);
                    listener.Start();
                    lock (this)
                    {
                        cTcpSocketServerThread ServerThread = new cTcpSocketServerThread(this);
                        new Thread(new ThreadStart(ServerThread.RunThread)).Start();
                        ServerSockets.Add(ServerThread);
                    }
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Waiting for connection at port " + ListenPort.ToString());
                }
                catch (SocketException se)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Could not create socket server thread: " + se.Message);
                }
            }
        }
        public cTcpSocketClient(cTcpSocket tcpSocket, string sServerAddress, int iReconnectInterval, bool bConnectAutomatically)
        {
            TcpSocket            = tcpSocket;
            ReconnectInterval    = iReconnectInterval;
            ConnectAutomatically = bConnectAutomatically;

            try
            {
                IPAddress[] ips;
                ips = Dns.GetHostAddresses(cHelper.Item(sServerAddress, 0, ':'));

                // Lookup some IPv4 address (fails in Windows 7 otherwise)
                foreach (IPAddress ip in ips)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        ServerAddress = ip;
                        break;
                    }
                }

                /*
                 *  IPHostEntry host = Dns.GetHostEntry(cHelper.Item(sServerAddress, 0, ':'));
                 *
                 *  // Lookup some IPv4 address (fails in Windows 7 otherwise)
                 *  foreach (IPAddress ip in host.AddressList)
                 *  {
                 *    if (ip.AddressFamily == AddressFamily.InterNetwork)
                 *    {
                 *      ServerAddress = ip;
                 * break;
                 *    }
                 *  }
                 */

                ServerPort = Int32.Parse(cHelper.Item(sServerAddress, 1, ':'));
                if (ServerPort > 0 && ServerPort < 65536 && ServerAddress != null)
                {
                    ThreadIsRunning    = true;
                    ClientThread       = new cTcpSocketClientThread(this);
                    PleaseTryToConnect = ConnectAutomatically;
                    new Thread(new ThreadStart(ClientThread.RunThread)).Start();
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Created connection thread for server " + sServerAddress);
                }
            }
            catch (SocketException se)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Could not create client thread: " + se.Message);
            }
        }