Android socket to achieve a simple chat applet

Android socket implements a simple chat applet for your reference. The specific contents are as follows

Server side:

Mobile terminal:

Notes:

1. Add network permissions

<uses-permission android:name="android.permission.INTERNET"/>

If it is not added, you cannot use socket to connect to the network. 2. Do not use the Android system UI interface in the newly started thread. In the run () method of echothread, there is the following code:

Handler. SendMessage (message) here; Send a message to the handler, and then the handler pops up a toast according to the message to show the connection failure. If you use it directly here

Toast.makeText(EchoActivity.this,0).show();

The following errors will be reported:

Can't create handler inside thread that has not called Looper.prepare()

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>