0

i'm trying to implement a telnet interface in a Processing sketch, to pass command and receive outputs on the console. I'm learning those days about the VT100 set of commands, so i was finally able to understand how was possible to reprint on already printed strings by moving the cursor.

I saw that it is also possible for the program to get input from the console, like with the Get cursor position command.

myClient.write("\033]6n");  //^[6n

The problem is that just print on the client interface the position, while i would like to have it back on the host. Someone know if and how is this possible?

Thank you

Here some example code:

import processing.net.*;

Server myServer;

void setup() {
  myServer = new Server(this, 10002); // Starts a myServer on port 10002

}

void draw() {
    Client thisClient = myServer.available();

    if (thisClient != null) {
      if (thisClient.available() > 0) {
          String recived = thisClient.readString();
          println(recived);
          thisClient.write("\033[2A\r\033[2K" + "You just wrote: " + recived + "\033[2K");       

          thisClient.write("\033[6n"); // this happear on the client side, i want it back somehow

    }
    }
}

void serverEvent(Server someServer, Client someClient) {
 someClient.write("\nhello, type something please...\n");
}
piLeoni
  • 131
  • 13
  • Can you please post a [mcve]? – Kevin Workman Mar 10 '17 at 16:34
  • It is `myClient.write("\033[6n");` The answer would be `\033[row;colR` _if_ the terminal supports this sequence. – Zsigmond Lőrinczy Mar 11 '17 at 12:04
  • Of course, and it does. But then is the people in front at the terminal who read that. How does the program running as a server, to know that data? – piLeoni Mar 11 '17 at 17:13
  • @KevinWorkman , you are right, just added. – piLeoni Mar 11 '17 at 17:27
  • The terminal(emulator) will send a `\033[row;colR` sequence. – Zsigmond Lőrinczy Mar 11 '17 at 18:45
  • @ZsigmondLőrinczy Actually what happen to me, using the osx Terminal, is that the terminal(emulator) just print it on his side, under my eyes, and then if i want to send it to the server side i have to press enter manually. So untill i send it back the server don't know, plus should be hidden to the user. – piLeoni Mar 11 '17 at 20:05
  • The most likely problem is that your client isn't actually reading from the terminal, so the terminal's responses don't go to the client. But there's no sample program for anyone to point out the problems. – Thomas Dickey Mar 11 '17 at 20:28
  • Hi @ThomasDickey, actually i just checked you website and looks you really know the vt100. So please help me to understand. Some cool terminal interfaces i accessed from the standard mac terminals looks to be able to understand where the sensor is, and even recognise mouse click. How is that done? And, what do you mean with the client not reading from the terminal? – piLeoni Mar 11 '17 at 21:40
  • The sequence you get back will appear as if the user typed it. So you need to check the user input for ANSI escape sequences (you might also want to do this to check for cursor key presses and such since they are escape sequences as well). – Fabel Aug 22 '17 at 09:58
  • You might need to disable canonization (usually enabled by default), which is a feature to buffer user input line by line and greatly reduce the bandwidth needed for the telnet protocol (but that can be considered minuscule either way nowadays of course). Otherwise the sequence might get caught in a line buffer, waiting for a new line character from the client. But this is just a guess, and I have no idea how to disable canonization in java. – Fabel Aug 22 '17 at 10:17

0 Answers0