在Android上是否有任何库可以管理TCP数据包? [英] Is there any library to manage TCP packets on Android?

查看:85
本文介绍了在Android上是否有任何库可以管理TCP数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python3本地LAN服务器脚本和Android设备之间建立连接.在测试时,我正在使用Android虚拟设备管理器.主要目标是使服务器和客户端之间的连接保持长时间(1小时).

I am trying to make connection between my Python3 local LAN server script and my Android device. While testing i am using Android Virtual Device Manager. Main target is to keep connection between server and clients for a long time (1 hour).

是否有一个好的库来发送和接收Android的数据包并使事情变得更容易?电话必须作为客户端,可以从服务器发送和接收数据.

Is there any good library to send and receive packets for an Android and to make things easier? Phone must work as a client which can send and receive data from server.

P.S.我定位到API 15.

P.S. Im targeting API 15.

我只设法将数据包发送到Python并在控制台中打印它们.我使用PrintWriter类发送数据,并使用java.net.Socket类打开套接字.试图读取传入的数据,但是有很多错误.

I only managed to send packets to Python and print them in console. I was using PrintWriter class to send data and java.net.Socket class to open a socket. Tried to read incoming data but there was a lot of errors.

推荐答案

凌空是一个非常好的库,用于在Android上发出异步HTTP请求.

Volley is a very good library for making asynchronous HTTP requests on Android.

Kryonet 是另一个非常好的Java网络库,可通过网络有效地运行TCP和UDP数据包Android也是如此.尽管每当我使用Kryonet时,我都使用该库编写了服务器端代码和客户端代码. Kryonet可以保持连接状态,因此,如果您在将服务器端代码从Python更改为Java时没有任何问题(Kryonet提供了可使用的示例),那么它将很好地满足您的目的. 使用此库,您甚至不需要对任何IP地址进行硬编码.您只需一行代码即可实时发现本地服务器.

Kryonet is another very good Java network library for sending TCP and UDP packets over network efficiently which runs on Android as well. Though whenever I used Kryonet, I wrote both the server side code and client side code using this library. Kryonet keeps the connection alive though, so if you don't have any issues changing your server side code from Python to Java (Kryonet has samples which you can use), then it will serve your purpose well. Using this library, you don't even need to hardcode any IP address. You can discover the local server in real time with just one line of code.

这篇关于在Android上是否有任何库可以管理TCP数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆