Init I have implemented a very basic port forwarding application, which takes inputs from the client and post it to a remote sftp server.
Sockets:
socket sock = server_sock.accept()
Socket client_sock = new Socket("remote sfpt server host",port);
client_sock.connect();
And input/output streams from each of these sockets are then copied using the following logic.
Copy:
byte b[] = new byte[65535];
int bytesRead = 0;
while ((bytesRead =in.read(b)) >= 0){
out.write(b, 0, bytesRead);
out.flush();
}
Problem
Both sftp server and the basic port forwarding server are hosted on the same machine.
Directly connecting to the sftp server, I can transfer a file at around 30MB/s, whereas
Transferring a file via the port forwarding server is always pegged at ~3MB/s-4MB/s.
I have tried with ServerSocketChannel as well but performance was same.
Question is how can I improve this basic port forwarding server's performance at per the sftp server?