in reply to Unknown characters

I suspect an encoding problem. Is the socket operating on bytes or characters? Can you view a hexdump of the source lines to check what bytes you're actually receiving? I believe the AIVDM payload is an ASCII-encoded bit vector. By default, sockets operate on bytes. Try using the :encoding pragma when you open the socket to set it to operate on characters.