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