Main server code with sockets