Код: Выделить всё
# Open the image
imageSend = Image.open("result.jpg").tobytes()
# Get the size of the byte array
tam_respuesta = len(imageSend)
# Send the size of the image
cliente_socket.sendall(struct.pack('!I', tam_respuesta))
# Send the image
cliente_socket.sendall(imageSend)
Код: Выделить всё
private fun recibirMensaje(socketChannel: SocketChannel): String? {
return try {
// Receive the message size
val tamMensajeBuffer = ByteBuffer.allocate(4)
while (tamMensajeBuffer.hasRemaining()) {
if (socketChannel.read(tamMensajeBuffer)
Подробнее здесь: [url]https://stackoverflow.com/questions/78666243/sending-an-image-from-python-to-kotlin-with-sockets-fails-on-tranforming-byte-ar[/url]