tags:

views:

152

answers:

0

Hello all.

Im having a problem using the org.apache.commons.net.telnet.* library in my android application and i was hoping someone could help me!

I have implemented an app which uses telnet to communicate with a remote server and all works fine, the problem i have is when i call TelnetClient.disconnect() the method does not return. When calling the method when running a test case (meaning sans android, just through eclipse) it returns immediatly, but on android something is screwing it up. My test case looked something like

TelnetClient telnet = new TelnetClient();
telnet.connect(ipAddress, port); 
telnet.disconnect(); //HERE

Could anyone enlighten me as to why this may be?

if i obtain an inputstream from the connected telnet object and some info is sent from the telnet server after disconnect has been called, it can cause the method to return and closes the comm thread which was created by calling .connect(..), which makes me think there is some sort or lock being held somewhere?

What would the findamental difference be between the davlik VM or android OS and my Java VM and XP machine to cause the behavoiur?

Thanks for any help, stack traces below!

Dori

I have a stack trace from the comm thread created by the TelnetClient.connect() at the time the ANR appears (as a result of the disconnect call indefinatly hanging)

"Thread-15" daemon prio=6 tid=17 NATIVE | group="main" sCount=1 dsCount=0 s=N obj=0x43812d90 self=0x1be528 | sysTid=1403 nice=-2 sched=0/0 handle=2703408 at org.apache.harmony.luni.platform.OSNetworkSystem.receiveStreamImpl(Native Method) at org.apache.harmony.luni.platform.OSNetworkSystem.receiveStream(OSNetworkSystem.java:236) at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:550) at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:87) at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:67) at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:177) at java.io.BufferedInputStream.read(BufferedInputStream.java:259) at java.io.PushbackInputStream.read(PushbackInputStream.java:160) at org.apache.commons.net.io.FromNetASCIIInputStream._read(FromNetASCIIInputStream.java:77) at org.apache.commons.net.io.FromNetASCIIInputStream.read(FromNetASCIIInputStream.java:175) at org.apache.commons.net.io.FromNetASCIIInputStream.read(FromNetASCIIInputStream.java:138) at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:177) at java.io.BufferedInputStream.read(BufferedInputStream.java:259) at org.apache.commons.net.telnet.TelnetInputStream._read(TelnetInputStream.java:122) at org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:564) at java.lang.Thread.run(Thread.java:1060)

and also from the thread calling .disconnect() (which for my test case is just on the main thread)

DALVIK THREADS: "main" prio=5 tid=3 MONITOR | group="main" sCount=1 dsCount=0 s=N obj=0x4001ab08 self=0xbc60 | sysTid=1390 nice=0 sched=0/0 handle=-1343996920 at java.io.BufferedInputStream.close(BufferedInputStream.java:~166) at org.apache.commons.net.telnet.TelnetInputStream.close(TelnetInputStream.java:535) at java.io.FilterInputStream.close(FilterInputStream.java:81) at java.io.BufferedInputStream.close(BufferedInputStream.java:167) at couk.mypackage.comm.TelnetClient.closeTelnet(IGSTelnetClient.java:441) at couk.myoackage.comm.Translator$1.handleMessage(IGSTranslator.java:65) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4203) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) at dalvik.system.NativeStart.main(Native Method)

EDIT

if i close the output and input streams explicitly (which the javaDoc says NOT to be, but to call disconnect() instead. then i can close the connection, ie

out.close();
in.close();
telnet.disconnect();

im confused!