public TCPIP_Channel(int nPort, string strIP_Address, int nMachine_ID = -1, int nAnalyseTypeID = -1, int nType = -1, TCPIP_Helper.TCPIPHelper parent = null) { this.nType = nType; this.parent = parent; this.nPort = nPort; // get the TerminationString if exist strTerminationString = myHC.GetTerminationStringFromTCPIPConfigurationByMachine_ID(nMachine_ID); analyser = new TCPIP.InterfaceAnalyse(nMachine_ID, this, nAnalyseTypeID); if (nType == 0) { tcpip_Server = new TCPIP_Server(nPort, nMachine_ID, nAnalyseTypeID, analyser, strTerminationString, parent); } if (nType == 1) { tcpip_Client = new TCPIP_Client(nPort, strIP_Address, nMachine_ID, nAnalyseTypeID, analyser, strTerminationString, parent); } }
public TCPIP_Server(int nPort, int nMachine_ID = -1, int nAnalyseTypeID = -1, TCPIP.InterfaceAnalyse analyser = null, string strTerminationString = null, TCPIP_Helper.TCPIPHelper parent = null) { this.nMachine_ID = nMachine_ID; tcpListener = new TcpListener(IPAddress.Any, nPort); listenThread = new Thread(new ThreadStart(ListenForClients)); listenThread.Name = "TCP/IP-Server Thread"; listenThread.Start(); // tcpListener = new TcpListener(IPAddress.Any, nPort); this.parent = parent; this.analyser = analyser; this.nPort = nPort; this.strTerminationString = strTerminationString; // Set the Interval to 5 seconds (5000 milliseconds). TCPIPServerTimer.Interval = 5000; TCPIPServerTimer.Enabled = true; TCPIPServerTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); }
public TCPIP_Client(int nPort, string strServername, int nMachine_ID = -1, int nAnalyseTypeID = -1, TCPIP.InterfaceAnalyse analyser = null, string strTerminationString = null, TCPIP_Helper.TCPIPHelper parent = null) { this.parent = parent; this.strServername = strServername; this.nPort = nPort; this.strTerminationString = strTerminationString; this.analyser = analyser; /* create a new client object */ myClient = new TcpClient(); /* Vital: Create listening thread and assign it to ListenThread() */ tListen = new Thread(new ThreadStart(ListenThread)); /* Start listening thread */ tListen.Start(); // Hook up the Elapsed event for the timer. TCPIPReconnectTimer.Elapsed += new ElapsedEventHandler(OnReconnetTimedEvent); // Set the Interval to 10 seconds (10000 milliseconds). TCPIPReconnectTimer.Interval = 10000; TCPIPReconnectTimer.Enabled = true; // check every n seconds if the channel is alive TCPIPCheckTimer.Elapsed += new ElapsedEventHandler(OnCheckTimedEvent); // Set the Interval to n seconds (n*1000 milliseconds). TCPIPCheckTimer.Interval = 1000; TCPIPCheckTimer.Enabled = true; // try to connect, if servername and port is given if (strServername.Length > 0 && nPort > 0) { Connect(); } else { WriteLoggEntry((int)Definition.ThorLogWindows.COMMUNICATION, "no servername and/or no port number available " , (int)Definition.Message.D_ALARM); } }