I am trying to make a simple message application on Android with Apache Mina. I am getting IllegalStateException
when calling connect(new InetSocketAddress(HOSTNAME, PORT))
.
Here is my client code:
http://pastebin.com/NR2H6X0t
Here is my server code:
http://pastebin.com/Q5fQnu2p
And here is the logcat output:
I am testing my apllications in same wifi network with a tablet and phone.
Even I can't see anything wrong with your code. But the LogCat says
org.apache.mina.transport.socket.nio.NioSocketConnector.connect()
ofNioSocketConnector.java
class at line# 185) your application is throwingNetworkOnMainThreadException
. First fix that than check if you are getting the same error.Apart from above I have a suggestion (for readability purpose): In
connectToServerButtonClicked()
of ClientActivity instead of usingbetter use
Edited: On request of @alkis coping my answer from comment below to answer part for better redability
NetworkOnMainThreadException
: This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your network related code in AsyncTask.