Beginner question: binary data and socket.send

Discussion in 'Python' started by Boris Epel, Dec 21, 2009.

  1. Boris Epel

    Boris Epel Guest

    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
    Boris Epel, Dec 21, 2009
    #1
    1. Advertising

  2. On Mon, Dec 21, 2009 at 3:31 PM, Boris Epel <> 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:  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
    Stephen Hansen, Dec 21, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    908
  2. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    218
    Chris Reay
    Nov 4, 2003
  3. Thomas Rachel
    Replies:
    0
    Views:
    199
    Thomas Rachel
    Jan 7, 2013
  4. Steven D'Aprano
    Replies:
    1
    Views:
    123
    Chris Angelico
    Jan 7, 2013
  5. Philipp Hagemeister
    Replies:
    0
    Views:
    153
    Philipp Hagemeister
    Jan 8, 2013
Loading...

Share This Page