Reputation: 313
I'm currently working on getting a python socket to send an integer to a java socket, so the java socket can read in a byte array that represents a string after this step.
I've tried sending the int in a struct but that returns a massive number on the java side.
p = struct.pack('i', len(data))
clientsocket.send(p)
Upvotes: 4
Views: 847
Reputation: 188
https://docs.python.org/2/library/struct.html
Check out 7.3.2.1. When sending any data over the network always convert it to network byte-order. Your above code would be:
p = struct.pack('!i', len(data))
clientsocket.send(p)
Upvotes: 2