Hey guys so I'm just trying to make a tcp proxy to learn and for fun.
I successfully accept the first bytes from the client but all i get is this byte array:
60, 112, 111, 108, 105, 99, 121, 45, 102, 105, 108, 101, 45, 114, 101, 113, 117, 101, 115, 116, 47, 62, 0
which translates to this utf8
<policy-file-request/>
And thats all i get whenever 059's or the new vanilla build tries to connect. However when i send this to the server, I get an instent connection reset.
I'm kinda stuck on this step, any tips? Some code is attached for reference. I'm thinking maybe its because I'm not reading the socket properly?
Proxy Accepting connection from client & reading packet
Code:
fun start(){
val socketBuilder = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp()
val proxy = socketBuilder.bind(InetSocketAddress("localhost", 2050))
runBlocking {
while(true) {
val clientSocket: Socket = proxy.accept()
launch {
println("Connection accepted: ${clientSocket.remoteAddress}")
val clientInput = clientSocket.openReadChannel()
val clientPacket = clientInput.toByteArray()
if(clientPacket.isNotEmpty()){
println("Client packet received: ${clientPacket.size} bytes")
for(b: Byte in clientPacket){
print("$b, ")
}
}
}
}
}
}
Attempting to forward what i got from the client to the server & seeing if i get a response (ends up only in an instant connection reset)
The server IP that I'm connecting to is USWest (54.215.224.118) on port 2050
Code:
runBlocking {
val serverSocket = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().connect(InetSocketAddress("54.215.224.118", 2050))
val input = serverSocket.openReadChannel()
val output = serverSocket.openWriteChannel()
val policy = byteArrayOf(60, 112, 111, 108, 105, 99, 121, 45, 102, 105, 108, 101, 45, 114, 101, 113, 117, 101, 115, 116, 47, 62, 0)
// output.writeStringUtf8("<policy-file-request/>\n")
output.writeFully(policy)
output.flush()
while (true){
val serverPacket = input.toByteArray()
if(serverPacket.size > 0){
for(c in serverPacket){
print("$c, ")
}
}
}