This is a simple example of use of TelnetClient. An external option handler (SimpleTelnetOptionHandler) is used. Initial configuration requested by TelnetClient will be: WILL ECHO, WILL SUPPRESS-GA, DO SUPPRESS-GA. VT100 terminal type will be subnegotiated.
Also, use of the sendAYT(), getLocalOptionState(), getRemoteOptionState() is demonstrated. When connected, type AYT to send an AYT command to the server and see the result. Type OPT to see a report of the state of the first 25 options.
author: Bruno - D'Avanzo
Tim Moores wrote:Using a separate thread is likely not the answer. And the code still uses println in a way that's at odds with the article I mentioned - are the circumstances such that you can rule out that as a problem?
Also, can you not use a ready-to-use 3rd party library?
04-03 09:29:28.040 2754-2754/? W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
04-03 09:29:28.040 2754-2754/? W/System.err: at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
04-03 09:29:28.040 2754-2754/? W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:154)
04-03 09:29:28.040 2754-2754/? W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122)
04-03 09:29:28.040 2754-2754/? W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
04-03 09:29:28.040 2754-2754/? W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
04-03 09:29:28.040 2754-2754/? W/System.err: at java.net.Socket.connect(Socket.java:882)
04-03 09:29:28.040 2754-2754/? W/System.err: at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
04-03 09:29:28.040 2754-2754/? W/System.err: at org.apache.commons.net.SocketClient.connect(SocketClient.java:209)
04-03 09:29:28.040 2754-2754/? W/System.err: at it.rockopera.scsremote.MainActivity$6.onClick(MainActivity.java:385)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.view.View.performClick(View.java:4756)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.view.View$PerformClick.run(View.java:19749)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.os.Looper.loop(Looper.java:135)
04-03 09:29:28.040 2754-2754/? W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5221)
04-03 09:29:28.040 2754-2754/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
04-03 09:29:28.040 2754-2754/? W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
04-03 09:29:28.040 2754-2754/? W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
04-03 09:29:28.040 2754-2754/? W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-03 09:29:28.040 2754-2754/? E/TELNET: no
simone giusti wrote:With Commons Net installed, I tried these simple test but I get an exception .. Any hints ???
Ron McLeod wrote:
simone giusti wrote:With Commons Net installed, I tried these simple test but I get an exception .. Any hints ???
Are you are running this code in the main/UI thread? If you are, then try running it in an AsyncTask instead - network operations aren't normally allowed on the main thread.
For testing though, you should be able to alter the thread policy as you did in your first two examples to permit network operations on the main thread - but this may cause your UI to become unresponsive.
simone giusti wrote:... I can't find information on using this library.
... once the connection is on, how can i send a command to server (plain text)
... how can I read server response (plain text)
simone giusti wrote:... have I to implement multithreading to solve the problem I started from or this library offers this function builded-in ??
Ron McLeod wrote:In your application - does the server-side actually use telnet protocol, or does it just send/receive raw data over the socket?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |