Fix send and receive function.

Fix send and receive functions so they now work without error. It is
likely there are still bugs. Also fix the test program 'chat.py'.
'chat.py' interacts very strangly with the user, but works.