zerovm/zerocloud — pull request #87 by larsbutler (2014-07-03 10:23:58+00:00)
Title: test: use `send`, not `sendto` on connected socket

Fixes https://github.com/zerovm/zerocloud/issues/86.

According to the Python docs
(https://docs.python.org/2/library/socket.html#socket.socket.sendto),
you should not use `socket.sendto` if a socket is already connected.

Linux (Ubuntu 12.04) seems to be forgiving of this behavior, but when I
run tests on OSX, I get several `socket.error: [Errno 56] Socket is
already connected` errors in the test suite.

This behavior can be demonstrated with the following Python script:

---
import socket

receiver = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

addr = ('127.0.0.1', 27000)
receiver.bind(addr)
sender.connect(addr)

num_bytes = sender.send(b'foo')
print('Received: %s' % receiver.recv(num_bytes))

num_bytes = sender.sendto(b'bar', addr)
print('Received: %s' % receiver.recv(num_bytes))
---

On Linux, this works and the received messages are printed.
On OSX, the `sendto` calls raises a `Socket is already connected` error.