Java Telnet Apache Commons: How to send functions keys?

╄→гoц情女王★ 提交于 2019-12-12 05:27:17

问题


I am programming a Java connection to a server using the Apache commons telnet library. I have modified the example code at http://www.java2s.com/Code/Java/Network-Protocol/ExampleofuseofTelnetClient.htm to connect to our server and preform tests. Everything seems to work fine but I cannot figure out how to send function key presses over telnet.

After using a sniffer with our IBM 3151 emulator for the function key 'F9' I got the value: '/033i/r', but simply just typing this in does not work. I figure it is just sending those text characters when I simply type them.

I'd imagine that I just missing something simple but I cannot seem to find any information after searching for a few hours.


回答1:


After searching for a bit longer I found that I had to send the ASCII hex characters in a byte array to the outputStream of the telnet session that corresponded to the terminal type I was using.

Thus to send '/033i/r' which is the code for the function key: 'F9', I created the following byte array:

byte[] toSend = new byte[] { (byte)0x1b, (byte)0x69, (byte)0x0d } ;

So you need to know which terminal emulation you are using for your telnet connection, and what the function keys map too.



来源:https://stackoverflow.com/questions/35181877/java-telnet-apache-commons-how-to-send-functions-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!