最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论