Server api sockets

Initial implementation of sockets server along with a few bug fixes.