Hi,

A couple things you can do to try to narrow down the problem:

(1) A lack of output from the Java client indicates that the connection is 
(probably) established and perhaps the client is simply waiting for some 
(potentially non-existent) response from the server. Try setting a short 
deadline on the client side to verify that nothing is hanging there: 
See https://grpc.io/blog/deadlines/ for examples of setting a client-side 
deadline. 

(2) Check if the Python server is working properly without the Java client 
involved, ideally via grpc_cli 
(https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md) or else 
a simple Python client.

Best,

Eric

On Saturday, November 30, 2019 at 12:10:56 AM UTC-8, Rahul Miryala wrote:
>
> Hi All,
>
> Kind request to all of you to help me in sorting out my problem.
>
> I have defined a message proto file for sending the png file from java 
> client to python server. Am able to launch python server correctly and 
> running the java client program to send it but am ending up with no result 
> and
> there is no error message also appears to find out the cause.
>
> Posting the code here. Please help me out in finding out the cause.
>
> syntax = "proto3";
>
> service FileServer {
>   rpc upload(stream Chunk) returns (Reply) {}
> }
>
> message Chunk {
>   bytes buffer = 1;
> }
>
> message Reply {
>   int32 length = 1;
> }
>
> Generated the stubs on both python and java sides.
>
> import os
> from concurrent import futures
>
> import grpc
> import time
>
> import file_upload_pb2, file_upload_pb2_grpc
>
> CHUNK_SIZE = 1024 * 1024  # 1MB
>
>
> def get_file_chunks(filename):
>     with open(filename, 'rb') as f:
>         while True:
>             piece = f.read(CHUNK_SIZE);
>             if len(piece) == 0:
>                 return
>             yield chunk_pb2.Chunk(buffer=piece)
>
>
> def save_chunks_to_file(chunks, filename):
>     with open(filename, 'wb') as f:
>         for chunk in chunks:
>             f.write(chunk.buffer)
>
>
> class FileServer(file_upload_pb2_grpc.FileServerServicer):
>     def __init__(self):
>         print("in Filervser")
>         class Servicer(file_upload_pb2_grpc.FileServerServicer):
>             def __init__(self):
>                 print("in service")
>                 self.tmp_file_name = 'stupid.poto'
>
>             def upload(self, request_iterator, context):
>                 print("in upload")
>                 save_chunks_to_file(request_iterator, self.tmp_file_name)
>                 return 
> file_upload_pb2.Reply(length=os.path.getsize(self.tmp_file_name))
>
>         print("in server")
>         self.server = 
> grpc.server(futures.ThreadPoolExecutor(max_workers=1))
>         file_upload_pb2_grpc.add_FileServerServicer_to_server(Servicer(), 
> self.server)
>
>     def start(self, port):
>         print("starting")
>         self.server.add_insecure_port(f'[::]:{port}')
>         self.server.start()
>
>         try:
>             while True:
>                 time.sleep(60*60*24)
>         except KeyboardInterrupt:
>             self.server.stop(0)
>
> if __name__ == '__main__':
>     FileServer().start(8888)
>
> Java file
>
> package test.fileupload;
> import io.grpc.ManagedChannel;
> import io.grpc.ManagedChannelBuilder;
> import io.grpc.stub.StreamObserver;
>
> import java.io.BufferedInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.util.logging.Logger;
>
> import com.google.protobuf.ByteString;
>
> import test.fileupload.FileUpload.Reply;
> import test.fileupload.FileUpload.Chunk;
>
> public class FileUploadClient {
>
> public static void main(String[] args) {
> ManagedChannel mChannel= ManagedChannelBuilder.forAddress("localhost", 
> 8888)
> .usePlaintext().build();
> FileServerGrpc.FileServerStub fileServerStub = 
> FileServerGrpc.newStub(mChannel);
> StreamObserver<Reply> streamReply = new StreamObserver<Reply>() {
>
> @Override
> public void onNext(Reply value) {
> Logger.getAnonymousLogger().info("on Next");
> }
>
> @Override
> public void onError(Throwable t) {
> Logger.getAnonymousLogger().info("on Error");
> }
>
> @Override
> public void onCompleted() {
> Logger.getAnonymousLogger().info("on Completed");
> }
> };
> StreamObserver<Chunk> chunkStream =fileServerStub.upload(streamReply);
> try {
>
> File file = new File("resizedCat.png");
> if (file.exists() == false) {
> Logger.getAnonymousLogger().info("File does not exist");
> return;
> }
> BufferedInputStream bInputStream = new BufferedInputStream(new 
> FileInputStream(file));
> int bufferSize = 1024 * 1024; // 512k
> byte[] buffer = new byte[bufferSize];
> int tmp = 0;
> int size = 0;
> while ((tmp = bInputStream.read(buffer)) > 0) {
> size += tmp;
> ByteString byteString = ByteString.copyFrom(buffer);
> Chunk req = Chunk.newBuilder().setBuffer(byteString).build();
> chunkStream.onNext(req); 
> }
> }catch (Exception e) {
> Logger.getAnonymousLogger().info("Exception"+e.getMessage());
> }
> chunkStream.onCompleted();
> }
> }
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/fbe641a0-c1e9-4f28-a9cb-e82b6d7e0f90%40googlegroups.com.

Reply via email to