Ejemplo n.º 1
0
    public String readline()
    {
        UserComponent.controlled_print("About to read new line from buffer...");
        while (this.running)
        {
            lock (this.lock_object)
            {
                UserComponent.controlled_print("Waiting for input in buffer... len=" +
                                               input_buffer.Length + " " + input_buffer);

                if (this.input_buffer.Length > 0)
                {
                    String[] message_list = input_buffer.TrimStart(' ').TrimStart('$').TrimStart(' ').Split('$');

                    if (message_list.Length > 1)
                    {
                        String message = message_list[0];
                        input_buffer = input_buffer.TrimStart(' ').TrimStart('$').TrimStart(' ')
                                       .Substring(message.Length + 1);
                        UserComponent.controlled_print("Returning message: " + message);
                        return(message);
                    }
                }
            }

            Thread.Sleep(1);
        }

        return(null);
    }
Ejemplo n.º 2
0
    private void data_receiver_thread_method()
    {
        while (running)
        {
            UserComponent.controlled_print("Looking for Python input...");
            byte[] b = new byte[INPUT_BUFFER_SIZE];
            this.input_socket.GetStream().Read(b, 0, INPUT_BUFFER_SIZE);

            UserComponent.controlled_print("Converted: " + System.Text.Encoding.UTF8.GetString(b));
            String received_string = System.Text.Encoding.UTF8.GetString(b).Trim((char)0);  //.Trim('#');
            UserComponent.controlled_print("received_string: " + received_string);

            lock (this.lock_object)
            {
                this.input_buffer += received_string;

                UserComponent.controlled_print("Buffer: " + this.input_buffer);
            }

            Thread.Sleep(1);
        }
    }