Improve networking

Add packet sending, improve receiving, fix a bug in stateful decoding
procedure, create decoding class.