UDP
Server
Execute
์๋ฒ๋ฅผ ์คํํ๊ธฐ ์ํด์๋ UdpServer๋ฅผ ์ด์ฉํ์ฌ ์์ฑํด์ค๋ค.
val server: Connection = UdpServer.create() // (1)
.port(9988)
.host("localhost")
.bindNow(Duration.ofSeconds(30)) // (2)
.onDispose()
.block()
Handle
๋ค์ด์จ ์์ฒญ์ ์ฒ๋ฆฌํ๊ธฐ ์ํด์ handle์ inbound, outbound๋ฅผ ํ์ฉํ ์ ์
.handle { inbound, outbound ->
outbound.sendString(Mono.just("hello"))
inbound.receiveObject()
.map { data -> data as DatagramPacket }
.map { packet -> String(packet.data) }
.doOnNext { println(it) }
.then()
}
Inbound ๋ ์์ฒญ์ console๋ก ์ฐ๊ณ , Hello๋ผ๋ ์๋ต์ ๋ด๋ ค์ฃผ๋ handler์ด๋ค.
Interceptor
์ฐ๊ฒฐ์ Lifecycle์ ํ์ฉํ์ฌ ์ธํฐ์ ํฐ๋ฅผ ๊ตฌํํ ์ ์๋ค.
.doOnBind { println("Bind :: ${it.bindAddress()}") }
.doOnBound { println("Bound :: ${it.address()}") }
.doOnUnbound { println("Unbound :: ${it.address()}") }
Option
์์ธoption์ ์ง์ ํด ์ค์ ์์ผ๋ฉฐ ์์ธ ์ต์
์ ๋งํฌ๋ฅผ ์ฐธ์กฐ
.option({OPTION}, {VALUE})
๋ก ์ง์ ํ ์์๋ค
Logger
Peer๋ค๊ฐ ํธ๋ํฝ์ ํ์ธํ๊ธฐ ์ํ ๋ก๊น
์ .wiretap(true)
๋ก ์ค์ ํ ์ ์๋ค
Client
๊ตฌํ์ฒด๋ง UdpClient๋ก ๋ฐ๋๊ณ Server๋ ๋์ผํ๊ฒ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
val connetor = TcpClient.create()
.port(9988)
.host("localhost")
.connectNow()
Last updated