scala socket client doesn't get response after sending binary data to python server -
i used scala socket client send binary data python server. found python socket server not able read data scala client. tried adding \r\n on tail of message, no effects. following scala client code please:
val s = new socket(inetaddress.getbyname(socket), 5000) s.setsotimeout(120*1000) val inputstream = s.getinputstream() val buffersource = new bufferedsource(inputstream) val out = new printstream(s.getoutputstream()) lazy val in = buffersource.getlines() //send data python server socket thedata:array[byte] = //the data comes sparkstreaming, it's byte array. out.println(thedata) out.flush() if(in.hasnext){ val json1 = in.next() }
the following python server code please:
class tcphandler(socketserver.streamrequesthandler): def handle(self): while true: cur_thread = threading.current_thread() self.data = self.rfile.read() if not self.data: break output=calculate256(self.data) self.wfile.write(json.dumps(output)+'\n')
the interesting thing if encode data base64 , use readline() instead of read() function, works. have transfer binary data processing, readline() not suitable us. highly appreciate kind help.
Comments
Post a Comment