Android Socket Connection fail

前端 未结 2 538
深忆病人
深忆病人 2021-01-17 01:08

I am trying to establish a connection between Android Client and C# Server .. My server is working fine except the android client is not working even after adding internet c

相关标签:
2条回答
  • 2021-01-17 01:40

    Check this link here, it is because since latest version of API, it is forbidden to perform networking operation called by the main thread, so you need to create another (background) thread to perform it instead.

    0 讨论(0)
  • 2021-01-17 02:03

    By the looks of it you are trying to perform networking operation on the main thread. Take a look at the log trace specially line android.os.NetworkOnMainThreadException.

    Android Developer: Network on Main Thread Exception

    Always do networking on a separate thread other than main. There are different ways to accomplish that as well e.g. you can use AsyncTask or start thread on your own.

    There are several posts on SO for this and Android Developer site. Here are a few links to get you going:

    Android Developer: Connecting to the network

    Android Developers Blog: Multithreading for performance

    0 讨论(0)
提交回复
热议问题