Given we have a socket connection (lets call it c1
) where we accept messages,
and we have N other socket connections we are about write the exact same message,
to determine which connection we want it to write to we only need to read the first few bytes from c1
, but the remaining of the bytes on the socket needs not to be loaded to java heap, just to be written to c2
...
So in nutshell what we want to do is.
we got event that we have bytes to read on c1
we read the first few bytes and determine that we know that we want to redirect this to c2
.
We take those first few bytes we already took from c1
write it to c2
and now we want to tell the system to write next N bytes from c1
to c2
directly (instead of c1 -> java heap -> c2).
Is there any means to do this in java?
Update:
Although the answer is to the point, if you are building something like this ( even not only for multiplexing but some little business logic ), I highly recommend you to go with ZeroMQ.