1

我正在尝试运行 2 个不同的 akka grpc 服务器,但是它们不能同时运行。我尝试在 localhost 端口 8080 上绑定一台服务器,在 localhost 端口 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}") }

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

4

1 回答 1

1

我宁愿使用localhost符号而不是127.0.0.1.

官方文档

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

在这个超级用户问题中更详细地解释了 , 和 addresslocalhost之间0.0.0.0的区别。127.0.0.1

于 2021-05-16T08:43:38.023 回答