Akka gRPC绑定错误的端口号



我正在尝试运行两个不同的akka grpc服务器,但它们不能同时运行。我尝试将一台服务器绑定在本地主机端口8080上,另一台绑定在本地机端口8090上。分离它们运行良好,但当我尝试将它们一起运行时,我会出现以下错误:

[ERROR] [05/13/2021 11:14:30.862] [Server-akka.actor.internal-dispatcher-6] [akka://Server/system/IO-TCP/selectors/$a/0] Bind failed for TCP channel on endpoint [/192.168.1.10:25520]
java.net.BindException: [/192.168.1.10:25520] Address already in use: bind

以下是我尝试创建它们时的代码:

val service: HttpRequest => Future[HttpResponse] =
StoreServiceHandler(new StoreImpl())
// Bind service handler servers to localhost:8080/8081
val binding = Http().newServerAt("127.0.0.1", 8080).bind(service)
// report successful binding
binding.foreach { binding => println(s"gRPC server bound to: ${binding.localAddress}") 

val service: HttpRequest => Future[HttpResponse] =
CommunicationChannelHandler(new CommunicationChannelImpl())
// Bind service handler servers to localhost:8080/8081
val binding = Http().newServerAt("127.0.0.1", 8090).bind(service)
// report successful binding
binding.foreach { binding => println(s"gRPC server bound to: ${binding.localAddress.getPort}") }

注意:print语句返回正确的端口,所以我不明白为什么它们不能一起运行/为什么它们都试图使用端口2552。

我宁愿使用localhost表示法而不是127.0.0.1

来自官方文件:

val bindingFuture = Http().newServerAt("localhost", 8080).bind(route)

localhost0.0.0.0127.0.0.1地址之间的差异在这个超级用户问题中有更详细的解释。

相关内容

最新更新