Updated socket handling

Changed socket calls from socket_*() to fread() and fwrite() to simplify
things (saved one line of code!) and made the socket persistent. This
"should" enable using AJAX calls to send and receive messages without
the need to log in for each AJAX call (still have to test it).