Jrpc

Think in Rpc

1. tcp test within shell

ServerSocket双向通信服务测试

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
26
27
28
29
30
31
32
33
34
35
public class JrpcService {
private static AtomicInteger count = new AtomicInteger(0);

public static void main(String[] ar) {
System.out.println("server start....");
try {
ServerSocket serverSocket = new ServerSocket(31543);
while (true) {
try (Socket connection = serverSocket.accept()) {
InputStream input = connection.getInputStream();
OutputStream output = connection.getOutputStream();

byte[] bytes = new byte[1024];
int len = input.read(bytes);
String request = new String(bytes, 0, len, StandardCharsets.UTF_8);

String result = count.getAndIncrement() + "--requst-->>" + request;
System.out.println(result);
output.write(result.getBytes(StandardCharsets.UTF_8));
output.flush();
System.out.println("write ennnnnnnnd");

} catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}

}

}

shell test code:

1
2
3
4
$ exec 9<>/dev/tcp/localhost/31543
$ echo -e "helloworld">&9
$ cat <&9
1--requst-->>helloworld