1, the operation of the socket is placed in a non-UI thread
?? In Android apps, in order to ensure the user experience of the app, you must respond as quickly as possible to the user's actions, so it is not recommended to put time-consuming actions on the UI thread in previous versions of Android. To the later version of Android3.0, there is a further restriction that the UI is not allowed in the non-UI thread, and it is forbidden to do long-response operations in the UI thread, such as networked operations.
?? The Networkonmainthread exception is thrown if the network operation is performed in the UI thread, so the socket operation must be placed within the child thread
2, to maintain the uniqueness of the Socekt instance (it is advisable to create it in singleton mode)
3. Open Internet access
<uses-permission android:name="Android.permission.INTERNET"/>
4. You can use the socket frame (Mina frame)
Android Socket programming note points