View Single Post
Old 01-20-2020, 11:36 AM   #8
pazos
cosiņeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 396
Karma: 435255
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by sherman View Post
It isn't suitable for Android use (because Go), but I created a wireless client UNCaGED that can be used for inspiration.

The calibre wireless device uses a custom protocol built upon TCP. It's basically JSON over TCP, with a bit of 'packet' framing. The format is basically:
123[0,{"some": "json"}], where 123 is the size of the following payload in bytes, 0 is an opcode, and the rest is JSON. Technically, the opcode and json object is also a JSON array...

Everything is text, including the payload size, which is a bit of a PITA to decode.

So, you have to roll your own communications code I'm afraid. No HTTP to be seen unfortunately.

EDIT: It's also a relatively chatty protocol. Lots of ACKS, but not for everything. Keep-alive messages etc.
EDIT2: Wireshark is your friend. It really helped me figure out the proper order of things.
Hi sherman, thanks for the feedback. I was aware of your UNCaGED project.


While is not impossible to use that in android is probably more work than repurposing https://github.com/sengjea/calibre-s...reService.java

The code there is old and some methods need to be updated (for example the way to get free space on the device is broken in modern android versions) but the protocol seem to work fine on my tests. My proposal would be using that as a base and, eventually, reduce boilerplate by using one of these wonderful square libraries, like https://github.com/square/moshi.

Anyways, if you want to port your UNCaGED project to android I would be happy to help. I have some experience in JNI/native apps, learned while trying to figure out how NativeActivity worked in the context of koreader.
pazos is offline   Reply With Quote