#include <unistd.h> // sleep()
#include "odai.h"
// these are the exported functions, supported parameter types
// are int, double and char *
static void
ret_void(const char *txt) {
return;
}
static int
ret_int(const char *txt) {
return (1234);
}
static double
ret_float(const char *txt) {
return (0.1234);
}
static char *
ret_string(const char *txt) {
return ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
int
main(int argc, char **argv) {
char *t = "this is a message";
double f = 0.1234;
Server *s = NULL;
int i = 0;
try {
s = new Server("localhost", 3000);
} catch (int err) {
exit(1);
}
// export functions to make them callable remotely
s->reg("v ret_void(s)", (void *)ret_void);
s->reg("i ret_int(s)", (void *)ret_int);
s->reg("f ret_float(s)", (void *)ret_float);
s->reg("s ret_string(s)", (void *)ret_string);
// send every second a message to all connected clients
while (true) {
sleep(1);
s->msg("message(i, f, s)", i++, f+i, t);
}
delete (s);
return (0);
}