Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
srikanth chadalavada
747 Pointssmack api for android, Connection.isConnected().
I am testing my chat app on android.
one of the test scenarios is when I turn off the wifi on my server, The client thinks it is still connected, because isConnected() method returns true.
So I am unable to validate the connection in this particular scenario. Any thoughts on this problem? Thank you.
1 Answer
Ben Jakuben
Treehouse TeacherBy "turnn off wifi on my server", do you mean you are disconnecting the server that you are using as the back-end? In that case the phone will still be connected to the Internet, but when it attempts to connect to your service it should get an error. You'll need to add error handling when that attempt to connect is made.
srikanth chadalavada
747 Pointssrikanth chadalavada
747 PointsYes, I am the disconnecting the server, my call for reconnect method is done only when isConnected() returns false, but it returns true in this case(it lies). Thank you Ben.
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherI am not familiar with the Smack API, but I took a quick look at their documentation. Perhaps you could try
ConnectionConfiguration#setReconnectionAllowed(boolean). From the docs:http://www.igniterealtime.org/builds/smack/docs/latest/documentation/connections.html