This commit is contained in:
Alex Yatskov 2011-09-03 09:05:56 -07:00
parent cfe77ab0c7
commit b3defb671c

View File

@ -23,11 +23,94 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// //
#include <stdio.h>
#include "metacall.hpp" #include "metacall.hpp"
using namespace metacall; using namespace metacall;
int main(int argc, char **argv) {
//
// Constants
//
static const int SERVER_PORT = 1338;
static const int SERVER_MAX_CLIENTS = 1;
//
// Local variables
//
static bool executeServer = true;
//
// Local functions (bound)
//
static void serverStop() {
printf("[S] Server stop request received\n");
executeServer = false;
}
//
// Local functions
//
static void server() {
Server server;
printf("[S] Starting server on port %d\n", SERVER_PORT);
if (!server.start(SERVER_PORT, SERVER_MAX_CLIENTS)) {
perror("[S] Unable to start server");
return;
}
printf("[S] Binding server functions\n");
server.binding()->bind("serverStop", serverStop);
printf("[S] Beginning client updates\n");
while (executeServer) {
server.advance();
}
printf("[S] Server shutting down");
server.stop();
}
static void client() {
Client client; Client client;
printf("[C] Connecting to server on port %d...\n", SERVER_PORT);
if (!client.connect("localhost", SERVER_PORT)) {
perror("[C] Unable to connect to server\n");
return;
}
printf("[C] Sending server shutdown request\n");
client.protocol()->invoke("serverStop");
while (client.connected()) {
client.advance();
}
}
//
// Program entry
//
int main(int argc, char **argv) {
if (fork() == 0) {
sleep(1);
client();
}
else {
server();
printf("Press enter to exit...\n");
getchar();
}
return 0; return 0;
} }