kotlin - Access raw non-TLS socket with Ktor Sockets - Stack Overflow

I'm using the current Ktor release 3.0.1 to implement a low-level socket client for a server softw

I'm using the current Ktor release 3.0.1 to implement a low-level socket client for a server software that has a bit of a weird behavior:

First, you connect to the server using a pseudo-HTTP request secured via TLS. After that, the connection is kept open and you may send unencrypted data via this connection.

I'm trying to implement this use case via Ktor Sockets, but it seems that my use case wasn't anticipated in the current library state, or at least not in an obvious way.

I tried opening the socket via

val rawSocket = aSocket(selectorManager).tcp().connect(host, port)
val secureSocket = rawSocket.tls(Dispatchers.Default)

However, after that, I cannot call rawSocket.openReadChannel() to read data from the unencrypted connection. Calling this method results in an IllegalStateException, because Socket.tls() already opens read and write channels on the raw connection to manage its own state.

Effectively, it seems that a raw socket isn't usable anymore as soon as the TLS layer is started on it. Is there a way to implement my use case with Ktor Sockets, or do I have to fall back to standard Java sockets, where managing sockets is more difficult but I can achieve what I want?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745576502a4633995.html

相关推荐

  • kotlin - Access raw non-TLS socket with Ktor Sockets - Stack Overflow

    I'm using the current Ktor release 3.0.1 to implement a low-level socket client for a server softw

    14小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信