client server python -C++
Question: I have written simple client(C++) server(Python) communication using boost
asio and protocol buffer. I pass array back and forth . My problem when I pass
array from server ( python) to client (C++) I have only about 50 elements of
my first array on the C++ output. How to solve this problem I have to pass 10
arrays with 10000 elements.

piece of code client c++ reading data on client :

    
    
                boost::asio::transfer_exactly(65536) */);
        boost::asio::streambuf b;
        boost::asio::streambuf::mutable_buffers_type bufs = b.prepare(10000000);
        size_t n = socket.receive(bufs);
    
        b.commit(n);
        std::istream is(&b);
        std::string s;
        is >> s;
    
    
         object1.ParseFromString(s);
         std::cout << object1.DebugString();
                // this line doesn't output allarray's elemenents. 
    
    
    }
    catch (std::exception& e)
    {
        //std::cerr << e.what(luuu) << std::endl;
    }
    std::cout << "\nClosing";
    std::string dummy;
        }
    

Python server:

    
    
        import socket 
        from test_pb2 import Person
        import dataf_pb2
    
        host = 'localhost'
        port = 10000
        backlog = 55
        size = 1024 
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
        s.bind((host,port))
        s.listen(backlog)
    
        element = dataf_pb2.ParticleMatrix()
        for i in range(1000):
        element.xPox.append(i * 0.53434)
    
        for i in range(1000):
        element.yPox.append( i * 0.53434)
    
        for i in range(1000):
        element.zPox.append(i * 0.53434)
    
        message= element.SerializeToString()
        element1 = dataf_pb2.ParticleMatrix()
    
        while 1: 
          client, address = s.accept()
          print ('Client connected')
          data = client.recv(50000)
          print data
          if data:
          object1 = dataf_pb2.ParticleMatrix()
          object1.ParseFromString(data)
          print object1.__str__()
          print object1.ListFields()
          client.send(message)
          client.close()
    


Answer: Have you attempted using
[sendall](https://docs.python.org/2/library/socket.html#socket.socket.sendall)
instead of just send? I've been working on a similar client/server (in pure
c++ though) and personally it looks like a buffer problem to me.

Another thing I would suggest is attempting to capture the loopback (if
client/server are running from same machine) and looking at the packets to see
what/how much data is actually getting sent. Wireshark is a useful tool for
this.

Also would be useful to add in some error handling on send/recv so you can
check total bytes that are actually being sent if you don't want to do the
packet capturing.

