admin管理员组文章数量:1022705
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?
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?
本文标签: kotlinAccess raw nonTLS socket with Ktor SocketsStack Overflow
版权声明:本文标题:kotlin - Access raw non-TLS socket with Ktor Sockets - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745576501a2157050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论