Hi I have a very simple Java server and two clients. One client is Java based and other is python based. When I send any string from Java client to java server or vice versa it works fine. When I send any string from Java to python it also works fine. But when I send a string from python which is generated by python json lib using json.dumps, I receive a buffer in Java containing desired data and null bytes. There is no indication of start or end of string. How do i convert it back to String of same length. Currently the string has a lot of null bytes after JSON data is finished thats why I wont be able to parse that string correctly.
Receive code for Java is like this.
byte[] receiveData = new byte[1024];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
CtrlChannel.getSocket().receive(receivePacket);
strData = new String(receivePacket.getData());
System.out.println("FROM PYTHON:" + strData);
Sender code of python is like this.
...
...
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
data = {}
data["type1"] = "type1"
data["type2"] = "type2"
data["type3"] = "type3"
data["type4"] = "type4"
data_string = json.dumps(data)
sock.sendto(data_string, (addr[0], 36963))
...
...
I am new to Java so there may be some silly mistake I am doing. PLease help.