Android Question we need a perfact telnet class,Network + AsyncStreams not perfact

hears

Active Member
Licensed User
Longtime User
in window telnet client .
we connect to ROUTER device,when input ,can press TAB button , the ROUTER will auto hint the correct words ,and instead input text.
i make app use
Network + AsyncStreams
it is can telnet,and display. but the last line of terminal have many problem.

1.TAB button function work not good. if i have press TAB,it will show hint words .but cannot change my input text auto,and my words will pass to next command input.

2.my text only can input to edittext .in windows telnet client directly write words to terminal window, in this way have good feeling to users.

i have find a JAVA packet,i have put in Attached Files.

who can help change to CLASS ? or do you have good advise here ?
 

Attachments

  • telnetd-2_0.zip
    472.4 KB · Views: 254

Star-Dust

Expert
Licensed User
Longtime User
There are some conceptual errors in your request:

1) The Android headboard is not like the Windows one. The TAB key can have different effects depending on which software keyboard is used. To have the TAB you have to insert a ButtonView (where it could not be covered by the keyboard) that you send in the ASCII TAB character. Eg.
B4X:
Sub ButtonTab_Click
   Astream.Write (Array As Byte (8))
   LabelTerminal.Text= LabelTerminal.Text & "[TAB]" & CRLF
End Sub
The same for ESC (27) CR (10) and LF (13)

2) To see what you write in the terminal window, you must enter it.
Es.

B4X:
Sub EditText_EnterPressed
    LabelTerminal.Text= LabelTerminal.Text & EditText.Text & CRLF
    Astream.Write(EditText.Text.GetBytes("UTF8"))
    EditText.Text=""
End Sub

3) It is possible to make excellent TelNet in B4X, I have made it without problems. In the forum you will find several examples of Chat Client Servers created in B4X, you can study them because the principle to create a CLIENT is the same whether you develop TelNet or develop other clients.
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
t
There are some conceptual errors in your request:

1) The Android headboard is not like the Windows one. The TAB key can have different effects depending on which software keyboard is used. To have the TAB you have to insert a ButtonView (where it could not be covered by the keyboard) that you send in the ASCII TAB character. Eg.
B4X:
Sub ButtonTab_Click
   Astream.Write (Array As Byte (8))
   LabelTerminal.Text= LabelTerminal.Text & "[TAB]" & CRLF
End Sub
The same for ESC (27) CR (10) and LF (13)

2) To see what you write in the terminal window, you must enter it.
Es.

B4X:
Sub EditText_EnterPressed
    LabelTerminal.Text= LabelTerminal.Text & EditText.Text & CRLF
    Astream.Write(EditText.Text.GetBytes("UTF8"))
    EditText.Text=""
End Sub

3) It is possible to make excellent TelNet in B4X, I have made it without problems. In the forum you will find several examples of Chat Client Servers created in B4X, you can study them because the principle to create a CLIENT is the same whether you develop TelNet or develop other clients.
thanks for you help.
my app display no problem now. now need send the under telnet control codes.use Astream.Write() send text is ok .but when send these ICA command not work.from under code,maybe i need write a setWait() ,for talk to Telnet server.

B4X:
public void doCharacterModeInit() throws IOException {
      sendCommand(WILL, ECHO, true);
      sendCommand(DONT, ECHO, true); //necessary for some clients
      sendCommand(DO, NAWS, true);
      sendCommand(WILL, SUPGA, true);
      sendCommand(DO, SUPGA, true);
      sendCommand(DO, TTYPE, true);
      sendCommand(DO, NEWENV, true); //environment variables
    }//doCharacterModeInit

    public void doLineModeInit() throws IOException {
      sendCommand(DO, NAWS, true);
      sendCommand(WILL, SUPGA, true);
      sendCommand(DO, SUPGA, true);
      sendCommand(DO, TTYPE, true);
      sendCommand(DO, LINEMODE, true);
      sendCommand(DO, NEWENV, true);
    }//doLineModeInit


 private void sendCommand(int i, int j, boolean westarted) throws IOException {
      rawWrite(IAC);
      rawWrite(i);
      rawWrite(j);
      // we started with DO OPTION and now wait for reply
      if ((i == DO) && westarted) setWait(DO, j, true);
      // we started with WILL OPTION and now wait for reply
      if ((i == WILL) && westarted) setWait(WILL, j, true);
      flush();
    }//sendCommand


 private void setWait(int WHAT, int OPTION, boolean WAIT) {
      switch (WHAT) {
        case DO:
          switch (OPTION) {
            case SUPGA:
              WAIT_DO_REPLY_SUPGA = WAIT;
              break;
            case ECHO:
              WAIT_DO_REPLY_ECHO = WAIT;
              break;
            case NAWS:
              WAIT_DO_REPLY_NAWS = WAIT;
              break;
            case TTYPE:
              WAIT_DO_REPLY_TTYPE = WAIT;
              break;
            case LINEMODE:
              WAIT_DO_REPLY_LINEMODE = WAIT;
              break;
            case NEWENV:
              WAIT_DO_REPLY_NEWENV = WAIT;
              break;
          }
          break;
        case WILL:
          switch (OPTION) {
            case SUPGA:
              WAIT_WILL_REPLY_SUPGA = WAIT;
              break;
            case ECHO:
              WAIT_WILL_REPLY_ECHO = WAIT;
              break;
            case NAWS:
              WAIT_WILL_REPLY_NAWS = WAIT;
              break;
            case TTYPE:
              WAIT_WILL_REPLY_TTYPE = WAIT;
              break;
          }
          break;
      }
    }//setWait

 private boolean WAIT_DO_REPLY_SUPGA = false;
    private boolean WAIT_DO_REPLY_ECHO = false;
    private boolean WAIT_DO_REPLY_NAWS = false;
    private boolean WAIT_DO_REPLY_TTYPE = false;
    private boolean WAIT_DO_REPLY_LINEMODE = false;
    private boolean WAIT_LM_MODE_ACK = false;
    private boolean WAIT_LM_DO_REPLY_FORWARDMASK = false;
    private boolean WAIT_DO_REPLY_NEWENV = false;
    private boolean WAIT_NE_SEND_REPLY = false;

    /**
     * Are we waiting for a WILL reply?
     */
    private boolean WAIT_WILL_REPLY_SUPGA = false;
    private boolean WAIT_WILL_REPLY_ECHO = false;
    private boolean WAIT_WILL_REPLY_NAWS = false;
    private boolean WAIT_WILL_REPLY_TTYPE = false;
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
But do you want to do it in Java or B4X?
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I would need to see the B4A code where you send the IAC codes. To understand the error

eg.
B4X:
Sub SendIAC(Code As Byte)
    AStream.Write(Array As Byte(255,Code))
End Sub
'Or
Sub SendArrayIAC(Code() As Byte)
    Dim Acode(Code.Length+1) As byte

    Acode(0)=255
    For I=1 To Code.Length
        Acode(I)=Code(I-1)
    Next
    AStream.Write(Acode)
End Sub
'Xor
Sub SendArrayIAC(Code() As Byte)
    AStream.Write(Array as Byte(255))
    AStream.Write(Acode)
End Sub

see this page
 
Last edited:
Upvote 0

hears

Active Member
Licensed User
Longtime User
I would need to see the B4A code where you send the IAC codes. To understand the error

eg.
B4X:
Sub SendIAC(Code As Byte)
    AStream.Write(Array As Byte(255,Code))
End Sub
'Or
Sub SendArrayIAC(Code() As Byte)
    Dim Acode(Code.Size+1) As byte

    Acode(0)=255
    For I=1 To Code.Size
        Acode(I)=Code(I-1)
    Next
    AStream.Write(Acode)
End Sub

see this page
Thank you very much, with you help i success send my command to server.

AStream.Write(Array As Byte(255,"command_code",24))

many times try ,i understand, my server API need first write 255,and end by 24. Center is my command_code
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Great. I do not know if the character 24 is always requested at the end. But if it works you okay :)
 
Upvote 0
Top