As a smaller part of a project I’m working on, to basically describe it;
Client A -> Server A >
(link direct via code) > Client B > Server B
,
one end being (A Side)
and the other (B Side)
respectfully,
The later goal of (direct via code) being replaced with another link,
Client A and Server B are their own self-contained program, which I’m trying to bridge with a tunnel.
I’ve tried so many things and I’m completely stumped on getting this working,
The current iteration of the code,
top of code:
Socket socketA, socketB;
Server (A) (who Client A connects to)
try {
ServerSocket ss = new ServerSocket(47352); //This is Server A
SocketB = ss.accept();
SocketA = new Socket("0.0.0.0", port); //Link from Client B to Server B
while(true){ //Un-needed, left over from other attempts at this
DataInputStream dIn = new DataInputStream(SocketB.getInputStream());
OutputStream dOut = SocketA.getOutputStream();
while (true) {
int length = dIn.available(); //dIn.readInt();
if(length>0) {
byte[] message = new byte[length];
dIn.readFully(message, 0, message.length); // read the message
dOut.writeInt(message.length); // write length of the message
dOut.write(message); // write the message
dOut.flush();
}
}
} catch ... //blah
(I will note, dIn.readInt was reporting values of 4 rather then 1, but this issue is outside of that scope)
Client (B) (who connects to Server b)
try {
if (SocketA != null & SocketB != null) {
DataInputStream dIn = new DataInputStream(SocketA.getInputStream());
DataOutputStream dOut = new DataOutputStream(SocketB.getOutputStream());
while (true) {
int length = dIn.available(); //dIn.readInt();
if(length>0) {
byte[] message = new byte[length];
dIn.readFully(message, 0, message.length);
dOut.writeInt(message.length);
dOut.write(message);
dOut.flush();
}
}
} catch ... //blah
Both of which run in their own thread,
The overall code currently is a desperate attempt to make this work,
Problems currently happening – and i’ve confirmed with wireshark, and data exchange just won’t work correctly, either not sending at all on A side, or not being past to B side.
I’ve also tried Non blocking TCP with Java NIO, but i couldn’t even get it to connect,
all the other solutions go along the same lines of what i’ve shown
What’s suppose to happen is a uninterrupted exchange of data between Client A to Server B – as if rest wasn’t there, what’s happen is it’s either hangs on read, reports the incorrect packet sizes, and Client B isn’t even attempting to send data coming from Server A, but is connected – again – verified with wireshark that the connection is happening, the finial idea is to remove the link directly with code and replace it with tunnel – but that’s not what im trying to do right now