使用Akka的Scala上具有SSL的TCP套接字 [英] TCP socket with SSL on Scala with Akka

查看:201
本文介绍了使用Akka的Scala上具有SSL的TCP套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Scala 2.10和Akka 2.3.4,我将一个简单的代理服务器组合在一起,该代理服务器接受传入的TCP连接,然后将这些消息代理到远程服务器。一切都在使用纯文本,但我仍然坚持使用SSL。

Using Scala 2.10 and Akka 2.3.4, I've put together a simple proxy server that accepts incoming TCP connections and then proxies those messages to a remote server. Things are working with plain text, but I'm stuck with SSL.

简而言之,这就是我启动用于接收连接的非安全服务器的方式:

Briefly, this is how I launch my non-secure server for incoming connections:

val server = system.actorOf(Props(new LegacyTCPServer), name = "my-tcp-server")

implicit val bindingTimeout = Timeout(1.second)
import system.dispatcher // execution context for the future

val boundFuture = IO(Tcp) ? Tcp.Bind(server, endpoint)

boundFuture.onSuccess { case Tcp.Bound(address) =>
  println("Fantastic! We have a connection: " + address)
}



<我可以通过telnet连接到该服务器,但是现在我想将no移到opensl。我想应该有一些配置选项,但是我似乎无法从文档中进行解析: http://doc.akka.io/docs/akka/2.3.4/scala.html

我见过使用akka 2.2.x且使用TCPPipelineHandler的一些(非功能性)示例,例如

I have seen some (non-functional) examples using akka 2.2.x that use a TCPPipelineHandler, e.g.,

https://groups.google.com/forum/#!topic/akka-user/auErrrk9wS0

https: //github.com/betehess/ping-pong-bot/blob/master/app/ircbot/IrcClient.scala#L183

但TCPPipelineHandler不会t似乎存在于akka 2.3.x中,所以感觉就像是一个死胡同。

but TCPPipelineHandler doesn't seem to exist in akka 2.3.x, so that feels like a dead end.

如果有人可以提供有关如何设置TCP的示例,我将非常喜欢使用当前版本的Scala&在SSL上使用套接字Akka。

I would love it if someone could provide an example of how to set up a tcp socket over ssl using current versions of Scala & Akka.

如果您需要更多信息,请告诉我。谢谢!

Please let me know if you'd like more information. Thanks!

推荐答案

spray是基于Akka IO构建的HTTP服务器/客户端。

spray is HTTP server/client built on top of Akka IO.

流水线基础设施和SslTlsSupport在 io.spray% spray-io% 1.3.1 软件包。我正在一个项目中使用它,目前正在研究中。有关更多详细信息,请参阅在Spray中如何为HttpServerConnection配置它。

There is a pipelining infrastructure and SslTlsSupport in "io.spray" % "spray-io" % "1.3.1" package. I use it in a project, I'm currently working on. For more details, please see how it is configured for HttpServerConnection in spray.

您需要重构代码以使用Spray的管道,根据我的经验,如果将代码分成多个阶段,每个阶段只占一小段,那么代码变得容易得多。

You would need to refactor your code to use pipelines from spray, from my experience code becomes much easier if you split your code into multiple stages each responsible for a small piece.

这篇关于使用Akka的Scala上具有SSL的TCP套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆