Android Socket Connection fail

前端 未结 2 539
深忆病人
深忆病人 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 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

提交回复
热议问题