Exemplo n.º 1
0
        private void Run(object parameters)
        {
            ListenerThreadParameters listenerThreadParameters = (ListenerThreadParameters)parameters;

            try
            {
                // Build listener for python engine
                listener = new TcpListener(listenerThreadParameters.port);
                listener.Start();
                //  Wait connection from python engine and if successful then create new socket to python engine
                pythonClient = listener.AcceptTcpClient();
                listenerThreadParameters.mainForm.PrintToLog((DateTime.Now.ToShortTimeString() + " :  Server trying start..."), Color.Black);
                listener.Stop(); // stop listening because python engine connected to GUI
                flagRun = true;
                // Asynchronic StateObject
                StateObject stateObject = new StateObject();
                stateObject.workSocket = pythonClient.Client;
                // Begins to asynchronously receive data from a connected socket with  python engine
                pythonClient.Client.BeginReceive(stateObject.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(Read_Callback), stateObject);
            }
            catch (SocketException se)
            {
                listenerThreadParameters.mainForm.PrintToLog(se.Message, Color.Red);
            }
            catch (Exception e)
            {
                listenerThreadParameters.mainForm.PrintToLog(e.Message, Color.Red);
            }
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            pythonListenerThread = new Thread(new ParameterizedThreadStart(Run));
            ListenerThreadParameters parameters = new ListenerThreadParameters();

            parameters.ip       = textBoxIP.Text;
            parameters.port     = int.Parse(textboxPort.Text);
            parameters.mainForm = this;
            pythonListenerThread.Start(parameters);
            StartPythonEngine();
        }
Exemplo n.º 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     pythonListenerThread = new Thread(new ParameterizedThreadStart(Run));
     ListenerThreadParameters parameters = new ListenerThreadParameters();
     parameters.ip = textBoxIP.Text;
     parameters.port = int.Parse(textboxPort.Text);
     parameters.mainForm = this;
     pythonListenerThread.Start(parameters);
     StartPythonEngine();
 }