|
|
Beginner question: binary data and socket.send
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
|
|
0
|
|
|
|
Reply
|
boep777 (1)
|
12/21/2009 11:31:38 PM |
|
On Mon, Dec 21, 2009 at 3:31 PM, Boris Epel <boep777@googlemail.com> wrote:
> 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: =C2=A0create socket, connect it, use send, close socket
> the unclear part: =C2=A0create 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
|
|
0
|
|
|
|
Reply
|
Stephen
|
12/21/2009 11:49:41 PM
|
|
|
1 Replies
465 Views
(page loaded in 0.363 seconds)
|
|
|
|
|
|
|
|
|