forked from reactive-ipc/reactive-ipc-jvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRxTcpServerSample.java
25 lines (19 loc) · 932 Bytes
/
RxTcpServerSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package io.rpc.rx.protocol.tcp;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.ripc.protocol.tcp.TcpServer;
import io.ripc.rx.protocol.tcp.RxTcpServer;
import io.ripc.transport.netty4.tcp.Netty4TcpServer;
import rx.Observable;
import static java.nio.charset.Charset.*;
public class RxTcpServerSample {
public static void main(String[] args) throws InterruptedException {
TcpServer<ByteBuf, ByteBuf> transport = Netty4TcpServer.<ByteBuf, ByteBuf>create(0);
RxTcpServer.create(transport)
.startAndAwait(connection -> connection.flatMap(bb -> {
String msgStr = "Hello " + bb.toString(defaultCharset());
ByteBuf msg = Unpooled.buffer().writeBytes(msgStr.getBytes());
return connection.write(Observable.just(msg).doOnCompleted(() -> System.out.println("Done!")));
}));
}
}