You are running network related operation on the main ui thread. You should use Asynctask or create a new thread.
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
Check the above link
I suggest you use asynctask.
http://developer.android.com/reference/android/os/AsyncTask.html
Use Asynctask and move your runTcpServer()
. Also remember you cannot update ui from a background thread. You will have to use runOnUiThread
or update ui in onPostExecute
Move all your network related operation to doInbackground(). Move the below to onPostExecute(). You can return the result of computation in doInbackground(). Based on the result update ui in onPostExecute
TextView tv= (TextView) findViewById(R.id.textView2);
//Log.d("TcpServer", "received: " + incomingMsg);
tv.append(incomingMsg);