+/* Exported: See ttt-server.h for documentation. */
+const char*
+ttt_server_get_host (ttt_server_t *server)
+{
+ return server->host;
+}
+
+/* Exported: See ttt-server.h for documentation. */
+const char*
+ttt_server_get_port (ttt_server_t *server)
+{
+ return server->port;
+}
+
+static const char *WELCOME_MESSAGE =
+"Welcome to ttt-server. So far, this program is still a demonstration\r\n"
+"TCP/IP server, acting something like a rather braindead chat server.\r\n"
+"The server is currently listening on:\r\n"
+"\r\n %s:%s\r\n"
+"\r\nTo test this, simply connect one or more clients to that host and port.\r\n"
+"For example:\r\n"
+"\r\n telnet %s %s\r\n"
+"\r\nOnce you have connected a client, the server will send each line of text\r\n"
+"it receives to all connected clients. The server reports client joins and\r\n"
+"departures on stdout.\r\n"
+"\r\nNote that to terminate the telnet client you type Control-], then\r\n"
+"<Enter>, then \"close\" (and <Enter>) at the \"telnet> \" prompt.\r\n"
+"\r\nHave fun!\r\n"
+"-Carl\r\n"
+"\r\nPS. At this point we're ready to leave the demonstration phase and to\r\n"
+"begin implementing TTTP (tic-tac-toe protocol) as well as fixing the\r\n"
+"protocol specifcation. We don't need a custom client to move forward on\r\n"
+"the server (that is one of the ideas behind using a telnet-compatible\r\n"
+"protocol), but a custom client would still be a fine project for a\r\n"
+"motivated beginning programmer.\r\n\r\n";
+
+static void
+_ttt_server_accept (void *closure, int client_socket)
+{
+ ttt_server_t *server = closure;
+
+ ttt_client_new (server, client_socket);
+}
+
+int
+main (int argc, char **argv)
+{
+ ttt_args_t args;
+ ttt_server_t server;
+ int socket;
+
+ ttt_args_parse (&args, argc, argv);
+
+ if (args.log_file)
+ xfreopen (args.log_file, "a", stderr);
+
+ socket = ttt_socket_create_server (args.host, args.port);
+
+ printf (WELCOME_MESSAGE, args.host, args.port, args.host, args.port);
+
+ ttt_server_init (&server, args.host, args.port);
+
+ while (1)
+ ttt_socket_accept (socket, _ttt_server_accept, &server);