 			fprintf(stderr, "problem creating socket: %s\n", strerror(errno));
 		}
 
-		sockaddr_in addr;
 		addr.sin_family = AF_INET;
 		addr.sin_port = htons(SERVER_SOCKET_PORT);
 		addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	}
+
+	~SocketServer() {
+		fflush(stdout);
+		if (sock != -1) {
+			int result = shutdown(sock, SHUT_RDWR);
+			if (result != 0) {
+				fprintf(stderr, "problem shutting socket");
+			}
+			result = close(sock);
+			if (result != 0) {
+				fprintf(stderr, "problem closing socket");
+			}
+		}
+	}
+
+	void *runSocketServer() {
 
 		bind(sock, (sockaddr*) &addr, sizeof(addr));
 		listen(sock, 5);

private:
	int sock;
	bool done;

public:
	SocketServer() {


#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

#include <iostream>
#include <fstream>

