Sending int from python socket to java socket

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 the string after this step.

I tried to send int to struct, but returns a massive number on the java side.

p = struct.pack('i', len(data))
clientsocket.send(p)
+4
source share
1 answer

https://docs.python.org/2/library/struct.html

Departure 7.3.2.1. When sending any data over a network, always convert it to network byte order. Your code above:

p = struct.pack('!i', len(data))
clientsocket.send(p)
+2
source

Source: https://habr.com/ru/post/1625411/


All Articles