Skip to content

Read from AsyncTcpSocket in separate Thread #263

Answered by eduard-vasinskyi
iEAmi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @iEAmi

AsyncTcpSocket is meant to be used inside an Eventloop. An Eventloop runs in a single thread, so every operation on AsyncTcpSocket should be performed from within that thread. This is the main idea behind using AsyncTcpSocket in the first place.

However, if you absolutely need to read from the AsyncTcpSocket in a separate thread, you can use a converter. First, you would need to convert the socket to a ChannelSupplier. Then you can convert a ChannelSupplier to a regular InputStream which can be used from a non-Eventloop thread.

A code could look something like this:

Eventloop eventloop = Eventloop.getCurrentEventloop();
ChannelSupplier<ByteBuf> channelSupplier = ChannelSupplier.o…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by iEAmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants