"요청 된 주소를 할당 할 수 없습니다"와 함께 실패하지만 실패Akka는 UDP를 보내는 <a href="https://doc.akka.io/docs/akka/2.5/scala/io-udp.html#bind-and-send-" rel="nofollow noreferrer">Bind (and Send) as in the docs</a>하려고
[akka : // UDP 테스트/시스템/IO-UDP-FF/선택기/$를/a0] 성공적으로 [/127.0.0.1:64387]에 바인딩
보내는 메시지 : bla
[akka : // udp-test/system/IO-UDP-FF/selectors/$ a/0]
이 요청 주소를 할당 [akka : // UDP 테스트/시스템/IO가-UDP가-FF는/선택기/$ A/0] 정지 후 DatagramChannel 데이터 닫기
대상 주소가 62.138.0.158
과 같은 공용 IP이거나 192.168.2.3
과 같은 로컬 네트워크 인 경우 ping
에 응답하면 위와 같이 실패합니다.
대상 주소가 모든 포트에서 127.0.0.1
(로컬 호스트) 인 경우이 성공합니다.
가 (예 : 192.168.2.2
) 로컬 네트워크 내 현재의 IP 로컬 주소를 변경 한 후을 성공
잘못된 IP 다르게 실패
[akka : // 기본// 무효 IP : 6969]
[/ ip-UDP-FF/selectors/$ a/1] 이름 확인에 실패했습니다.정확히 Simple Send in the docs과 같이 정확하게 수행하면이 성공합니다. 즉, Bind
이 SimpleSender
으로 바뀌 었습니다. 그러나 나는 또한 동일한 포트에서 청취 할 필요가 내가 Bind (and Send)의 의사로 일하기를 기대 말한다 :
보내는 데이터 그램을 재현하려면 메시지 보내기
을 사용하여 달성 :
import java.net.InetSocketAddress
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.io.{IO, Udp}
import akka.io.Udp.Send
import akka.util.ByteString
object Main extends App {
val system = ActorSystem("udp-test")
val destAddr = new InetSocketAddress("62.138.0.158", 6969)
private val props = Props(classOf[Listener], destAddr)
val udp: ActorRef = system.actorOf(props, "udp-actor")
Thread.sleep(500) //give time for the actor to be created
udp ! "bla"
}
class Listener(remote: InetSocketAddress) extends Actor {
import context.system
IO(Udp) ! Udp.Bind(self, new InetSocketAddress("localhost", 0))
def receive = {
case Udp.Bound(local) =>
context.become(ready(sender()))
case other =>
println(s"Received something else: $other")
}
def ready(socket: ActorRef): Receive = {
case msg: String =>
println(s"Sending msg: $msg")
socket ! Send(ByteString(msg), remote)
case other =>
println(s"Received something else: $other")
}
}
나는 macOS에서 실행 중이다.