概念
测试服务器和双向流式 RPC
在终端中演示 gRPC FTP 服务。
重新编译项目
1mvn clean install
运行服务器
1java -cp ftp-service-1.0.2.jar io.datajek.ftpservice.Application
服务器以非安全模式启动
1io.datajek.ftpservice.server.FTPServer - FTP Server started in IN-secure mode
读取文件的命令
1java -cp target/ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read testFile -server localhost
使用异步存根读取文件时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received request to read file testFile 2io.datajek.ftpservice.server.FTPService - Completed request to read file testFile
使用阻塞存根读取文件的命令
1java -cp target/ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read testFile -server localhost -blocking
使用阻塞存根读取文件时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received request to read file testFile 2io.datajek.ftpservice.server.FTPService - Completed request to read file testFile
读取不存在文件的命令
1java -cp target/ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read myFile -server localhost -blocking
读取不存在文件时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received request to read file myFile 2io.datajek.ftpservice.server.FTPService - File myFile doesn't exist 3io.datajek.ftpservice.server.FTPService - Completed request to read file myFile
读取不存在文件时客户端的消息
1Initiating synchronous read call with the server 2Received result from server: File myFile does not exist. 3Completed read call
获取文件属性的命令
1java -cp target/ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -attr "myTestFile sample.cpp sample.py testFile.txt" -server localhost
发送文件属性时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received file attributes request for myTestFile 2io.datajek.ftpservice.server.FTPService - Completed file attributes request for myTestFile 3io.datajek.ftpservice.server.FTPService - Received file attributes request for sample.cpp 4io.datajek.ftpservice.server.FTPService - Completed file attributes request for sample.cpp 5io.datajek.ftpservice.server.FTPService - Received file attributes request for sample.py 6io.datajek.ftpservice.server.FTPService - Completed file attributes request for sample.py 7io.datajek.ftpservice.server.FTPService - Received file attributes request for testFile.txt 8io.datajek.ftpservice.server.FTPService - Completed file attributes request for testFile.txt
接收文件属性时客户端的消息
1File names received: [myTestFile, sample.cpp, sample.py, testFile.txt] 2Sending request to get attributes of myTestFile 3Sending request to get attributes of sample.cpp 4Sending request to get attributes of sample.py 5Sending request to get attributes of testFile.txt 6Received result from server: 7name: "myTestFile" 8size: 7325 9creationTime: "2024-10-05T09:43:54.058Z" 10modificationTime: "2024-10-05T09:57:02.458Z" 11 12Received result from server: 13name: "sample.cpp" 14size: 125 15creationTime: "2024-03-09T06:48:53.463Z" 16modificationTime: "2024-03-09T06:48:53.463Z" 17 18Received result from server: 19File sample.py does not exist. 20Received result from server: 21name: "testFile.txt" 22size: 334 23creationTime: "2024-03-09T06:50:29.845Z" 24modificationTime: "2024-03-09T06:50:58.230Z" 25 26Completed get attributes call
请求和响应消息的顺序可能改变
1Sending request to get attributes of myTestFile 2Sending request to get attributes of sample.cpp 3Received result from server: 4name: "myTestFile" 5size: 7325 6creationTime: "2024-10-05T09:43:54.058Z" 7modificationTime: "2024-10-05T09:57:02.458Z" 8 9Received result from server: 10name: "sample.cpp" 11size: 125 12creationTime: "2024-03-09T06:48:53.463Z" 13modificationTime: "2024-03-09T06:48:53.463Z" 14 15Sending request to get attributes of sample.py 16Received result from server: 17File sample.py does not exist. 18Sending request to get attributes of testFile.txt 19Received result from server: 20name: "testFile.txt" 21size: 334 22creationTime: "2024-03-09T06:50:29.845Z" 23modificationTime: "2024-03-09T06:50:58.230Z" 24 25Completed get attributes call
Terminal
服务器消息,表示其已启动并正在运行
1io.datajek.ftpservice.server.FTPServer - FTP Server started in IN-secure mode
在 destOnServer 目录中创建示例文件
1cd destOnServer 2echo "This is my sample file" > testFile 3echo "#include <iostream> 4using namespace std; 5int main() { 6 cout << \"Hello, World!\" << endl; 7 return 0; 8}" > myFile.cpp 9ls
代码示例
1cd BiDiInsecureClientBinaries 2java -cp ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read testFile -server localhost
读取文件时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received request to read file testFile 2io.datajek.ftpservice.server.FTPService - Completed request to read file testFile
读取文件时客户端的消息
1SampleCLIClient - Initiating asynchronous read call with the server 2SampleCLIClient - Received result from server: This is my sample file 3 4SampleCLIClient - Completed read call
代码示例
1java -cp ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read testFile -server localhost -blocking
使用阻塞存根读取文件时客户端的消息
1SampleCLIClient - Initiating synchronous read call with the server 2SampleCLIClient - Received result from server: This is my sample file 3 4SampleCLIClient - Completed read call
代码示例
1java -cp ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -read sample.txt -server localhost
读取不存在文件时服务器的消息
1io.datajek.ftpservice.server.FTPService - Received request to read file sample.txt 2io.datajek.ftpservice.server.FTPService - File sample.txt doesn't exist 3io.datajek.ftpservice.server.FTPService - Completed request to read file sample.txt
读取不存在文件时客户端的消息
1SampleCLIClient - Initiating asynchronous read call with the server 2SampleCLIClient - Received result from server: File sample.txt does not exist. 3SampleCLIClient - Completed read call
获取文件属性的命令
1java -cp ftp-service-cli-client-1.0.2-jar-with-dependencies.jar io.datajek.ftpservice.cliclient.SampleCLIClient -attr "testFile sample.txt myFile.cpp" -server localhost
文件属性请求的服务器消息
1io.datajek.ftpservice.server.FTPService - Received file attributes request for testFile 2io.datajek.ftpservice.server.FTPService - Completed file attributes request for testFile 3io.datajek.ftpservice.server.FTPService - Received file attributes request for sample.txt 4io.datajek.ftpservice.server.FTPService - Completed file attributes request for sample.txt 5io.datajek.ftpservice.server.FTPService - Received file attributes request for myfile.cpp 6io.datajek.ftpservice.server.FTPService - Completed file attributes request for myfile.cpp
文件属性响应的客户端消息
1io.datajek.ftpservice.client.FTPServiceClient: Sending request to get attributes of testFile 2io.datajek.ftpservice.client.FTPServiceClient: Sending request to get attributes of sample.txt 3SampleCLIClient - Received result from server: name: "testFile" 4size: 23 5creationTime: "2024-10-22T07:44:02.180Z" 6modificationTime: "2024-10-22T07:44:02.180Z" 7 8SampleCLIClient - Received result from server: File sample.txt does not exist. 9io.datajek.ftpservice.client.FTPServiceClient: Sending request to get attributes of myfile.cpp 10SampleCLIClient - Received result from server: name: "myfile.cpp" 11size: 70 12creationTime: "2024-10-22T07:44:02.184Z" 13modificationTime: "2024-10-22T07:44:02.184Z" 14 15SampleCLIClient - Completed get attributes call