Sockets: Receiving C Struct

Discussion in 'Python' started by Johnny Venter, Aug 5, 2011.

  1. New to python and would like to test network/sockets with it.

    I am having a problem where I have setup the following:

    import socket, sys, struct

    HOST = '1.1.1.1'
    PORT = 153
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    data = struct.unpack('!I',s.recv(4))[0]

    s.close()

    print data


    What I would like to do is take the input from the server, and store it in an array. The type of data is int.

    Can someone help?


    Thanks, Johnny


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG/MacGPG2 v2.0.17 (Darwin)

    iQIcBAEBAgAGBQJOO975AAoJEBRo55dgl7RwAYoQAMX7Svf3DK4NTV+2RWw1r3Rs
    UZLQK6helvmz+ld3oKI9RUDAmmUjrALHK6cGqGJYk+vyu9l4PM7xRRsEI6JA37XM
    tzACZlqTUS1r8mtQglFyZt0ZVvzXy2z5rsQtct5+xWuLDj54UJ+rzvXhqGEEdj15
    OuHNkoPxardna6e4eF/yzF9n5gIlCcXde4l7qJJTPWYUH1h1mXc2D1jHW1SvZvcS
    wTn5tw+Kj5OLFjkIjWFetX4YjmZ285/jtvY1GLX9zq9dd9GwYN1f1/QRDfAk/hjO
    sglS8HJy1In6ohYp//Mh2ALQYMTDpZrWzlhMUasDO1rfdJCeUINbnmw/ervX428w
    wlr4rBaXL8d5d++NDz0Vg7J80U5CpxsqJYst78iYfn56tS1CvHuJ3FuFdlD8dEQh
    WmzgcCjU2Pc7xZaHYlZiNw8YEliKwNwYv7+XL0GSQIxTdf/j9lyOeJevn1xpGQy/
    9XUO3ojXeRB+3omZ9ESpSjIFxkgUcwtrJBwEemYUZzxO77W4ZmXRpwHgXU2kCOEB
    2UIv44QcpVrksHsLYus8Vu343ADBOyXOC17yNEsv6fRGs8Bc8k7rwT/sxxX13lPf
    4gwD92esiQNY/GKf97wJLKlwTHaodRQW1ByzPCmwAteaBkLa2xC7DJfCRyWmU3HI
    zYnN4+pWaJSvvHdvoZGp
    =1H0X
    -----END PGP SIGNATURE-----
     
    Johnny Venter, Aug 5, 2011
    #1
    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. RA Scheltema
    Replies:
    3
    Views:
    424
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    833
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,439
    Chris Fogelklou
    Apr 20, 2004
  4. Johnny Venter

    Fwd: Sockets: Receiving C Struct

    Johnny Venter, Aug 5, 2011, in forum: Python
    Replies:
    0
    Views:
    160
    Johnny Venter
    Aug 5, 2011
  5. Bigus

    Sockets: receiving data

    Bigus, May 21, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    178
    Bigus
    May 22, 2004
Loading...

Share This Page