encode/decode and recv_nowait

Added methods
- encode
- decode
- recv_nowait

Re-factored recv and send to avoid duplicate code.
Also added test for the new methods.