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?
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
How can I implement that ???
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?
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.
I moved code out of main thread and it works (connection is ok).
I can't find information on using this library.
I have 3 simple questions:
1) once the connection is on, how can i send a command to server (plain text)
2) how can I read server response (plain text)
3) have I to implement multithreading to solve the problem I started from or this library offers this function builded-in ??
Thanks !!
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)
Have to looked at the Apache Commons Net documentation? It has a couple of example telnet client applications.
simone giusti wrote:... have I to implement multithreading to solve the problem I started from or this library offers this function builded-in ??
If you need your connection to be long-lived, staying connected and interacting with the server even when the UI is not visible, a Bound Service might be a good fit.
Socket provides a TCP-based communcation channel between endpoints. Apache Commons Net builds on top of that by providing the client-side implementation of various application-level protcols (Telnet, FTP, NTP, etc.). If you were to just use Socket, you would need to support the telnet protcol yourself.