Correct wrong exception emmited by reading packets. Add a test for packet reading and correct some bugs related to packets.