简体   繁体   中英

Java / or Android IP tunnel

We need to tunnel a port on a cloud server to an Android device. Now, we're using a SSH client on Android (Jsch) to initiate a reverse port forward. This works, but we do not need / want the overhead of encryption / authentication.

Essentially, a simple IP tunnel that can be established from the client side (Android) to a server in the cloud.

Googling on this topic was not promising, so I thought I'd give it a try here and see if I can get any leads. Obviously we'd rather not build this ourselves from scratch.

This is actually rather simple to implement in Java. The tunneler app on the device opens two connections, one to the server and one to the service on the device. Now if you use Input-/OutputStreams (as as ooposed to nio Channels) you need 2 threads that are each reading on one of the InputStreams and just write everything they received to the opposite output stream. On the server you will need a similar process that gets it's two connections from ServerSocket.accept and needs to be able to find out which one is the tunneler and which it a client of the service (ie tests for the header of the tunneled protocol on incoming connections).

This becomes a bit more complicated if you want to be able to tunnel multiple connections at the same time. You would need to implement some sort of protocol for this to be able to dispatch the tunneled packets to multiple connections on the device if you want to avoid to open multiple tunnel connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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