Python - send/receive a numpy array in an Ethernet Packet
<p>I need to set up a network to transfer a numpy array from a host computer to a client computer.  This can be as simple as possible except I have to use 16 bit integers.  Am I doing it right?  Are there better functions/commands I should be using?  (Win7, 64bit, Python 2.7) So far, it seems to work but I am a total noob to networking and I haven't found a decent tutorial that explains how all this fits together.  (Please suggest one)  Thanks!</p>

<p>server.py</p>

<pre><code>import socket, time, numpy as np
myDict = {1:1, 2:2, 3:3}
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while 1:
    data = np.array(myDict.values(), dtype = np.int16).flatten()
    s.sendto(data, ('&lt;broadcast&gt;',5252))
    time.sleep(1)
</code></pre>

<p>client.py</p>

<pre><code>import socket, numpy as np
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('', 5252))
data = np.empty((1,6), dtype = np.int16)
s.recv_into(data)
print data
</code></pre>