/// <summary> /// Initialize this component /// </summary> public override void Initialize() { base.Initialize(); if (Simulate == eSimulate.SimulateDontAsk) { throw new ForceSimulateException("Always Simulate"); } try { Initialized = false; TCPIP tcpip = GetParent <TCPIP>(); if (tcpip == null) { throw new ForceSimulateException("Needs TCPIP parent"); } IPAddress GMasIP, LocalIP; IPAddress.TryParse(tcpip.IPAddress, out GMasIP); IPAddress.TryParse(tcpip.LocalIPAddress, out LocalIP); if (MMCConnection.ConnectRPC(GMasIP, 4000, LocalIP, 5000, new cbFunc(UCB.UserCallback), 0xEFFFFFFF, out m_connectHandle) != 0) { m_connectHandle = 0; throw new ForceSimulateException("Unable to Connect"); } _updateLoop = new BackgroundWorker(); _updateLoop.DoWork += new DoWorkEventHandler(UpdateLoop); //_bw = new AbortableBackgroundWorker() { WorkerSupportsCancellation = true }; //_bw.DoWork += new DoWorkEventHandler(WaitForData); //_bw.RunWorkerAsync(); Simulate = eSimulate.None; } catch (ForceSimulateException fsex) { throw fsex; } catch (Exception ex) { throw new ForceSimulateException(ex); } }
static void Main(string[] args) { string filename = "Config.xml"; byte[] sendData_byte = null; XML xml = new XML(filename); string address = xml.GetStrXML("/config/tcpip/address"); int port = xml.GetIntXML("/config/tcpip/port"); Carpark cp = new Carpark(); TCPIP tcpip = new TCPIP(address, port); Console.WriteLine("Running at IP:" + address + " Port: " + port.ToString() + "\n"); while (true) { Console.WriteLine("Host Server: Listening"); string recvData = Utils.Byte2StrAscii(tcpip.StartListen()); // Can be better if (recvData.Contains(Commands.complementaryFareCommand)) { sendData_byte = cp.GetComplementaryFare(); } else if (recvData.Contains(Commands.normalFareCommand)) { sendData_byte = cp.GetNormalFare(); } if (recvData.Contains(Commands.openGateCommand2_0)) { sendData_byte = cp.OpenGate2_0(); } if (sendData_byte != null) { tcpip.SendData(sendData_byte); } tcpip.StopListen(); } }
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); } }
//Cosntrutor... public Movements() { tcp = TCPIP.Instance; udp = UDP.Instance; }