简体   繁体   English

Android-在后台监听传入的TCP / Socket消息

[英]Android - Listening for incoming TCP/Socket messages in background

I am trying to write a little application which sends TCP messages (with a PrintWriter) to a JAVA Server running on PC. 我正在尝试编写一个小程序,该程序将TCP消息(带有PrintWriter)发送到PC上运行的JAVA服务器。 Now the Client should listen in background for incoming messages from the Server. 现在,客户端应在后台侦听来自服务器的传入消息。 How can I listen for incoming messages an update the GUI with the message from background-task? 如何通过后台任务中的消息更新GUI来监听传入消息?

You'll want to spin up a background thread for this. 您需要为此增加一个后台线程。 Probably the easiest way to go is to use an AsyncTask and then use onPostExecute, or publishProgress, to safely display your message in the UI. 可能最简单的方法是使用AsyncTask,然后使用onPostExecute或publishProgress在UI中安全显示消息。

Check out the Android docs on threads . 查看关于线程Android文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM