Beginner question: binary data and socket.send

B

Boris Epel

Hi! Please help with the problem:
send over TCPIP data packet organized as 6 bytes of identifier,
integer (LSB) and length of following binary data, binary data
the clear part: create socket, connect it, use send, close socket
the unclear part: create string with required data to use with send
what I tried:
buffer = [for i in range(23)];
buffer[0:5]="BBBBBB"
command = 0
buffer[6:9] = (command >> i & 255 for i in range(0,32,8))
datalength = 10
buffer[10:13] = (datalength >> i & 255 for i in range(0,32,8))
here i surrendered since buffer is a list of int and i need string ...
Suggestions are appreciated! boris
 
S

Stephen Hansen

Hi! Please help with the problem:
send over TCPIP data packet organized as 6 bytes of identifier,
integer (LSB) and length of following binary data, binary data
the clear part:  create socket, connect it, use send, close socket
the unclear part:  create string with required data to use with send
what I tried:

You probably want to take a look at the "struct" module to pack your
byte-strings with binary data.

HTH,

--S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top