Вопрос

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).

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. Im targeting API 15.

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.

Это было полезно?

Решение

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

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top