I have a simple application that opens a ServerSocket, and when connected, it connects to another server socket on the remote machine. To implement port forwarding, I use two streams: one that reads from the local input stream and the streams to the output stream of remote sockets and vice versa.
The implementation seems a little inefficient, and so I ask you if you know about a better implementation strategy or even use some kind of code to achieve this in your own way.
PS: I know that I can use IPTables on Linux, but this should work on Windows.
PPS: If you publish implementations for this simple task, I will create a control test to test all the given implementations. The solution should be fast for many small packets (~ 100 bytes) and robust data streams.
My current implementation is this (performed for each of two threads for each direction):
public static void route(InputStream inputStream, OutputStream outputStream) throws IOException { byte[] buffer = new byte[65536]; while( true ) {
java portforwarding
Daniel
source share