Sockets: Receiving C Struct

J

Johnny Venter

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-----
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top