int main(int argc, char **argv) { TRACEON(); if(argc == 2) { int port = atoi(argv[1]); TRACE("Acting as server: port=%d\n", port); MyServer bs; bs.run(port); } else if(argc == 4) { const char *host = argv[1]; int port = atoi(argv[2]); TRACE("Acting as client: host=%s port=%d\n", host, port); BlockSocket bs(host, port); if(bs.isConnected()) { TRACE("connected\n"); char s[256]; strcpy(s, argv[3]); int w = bs.write(s, strlen(s)); if(w != -1) { TRACE("wrote %d bytes\n", w); int r = bs.read(s, sizeof(s)); if(r != -1) { TRACE("read %d bytes\n", r); s[r] = 0; TRACE("response: '%s'\n", s); } else TRACE("Read error\n"); } else TRACE("Write error\n"); } else TRACE("Couldn't connect\n"); } TRACE("Done.\n"); return 0; }
int main(int argc, char *argv[]) { int port = atoi(argv[1]); MyServer server; server.run(port); return 0; }
int main(int argc, const char *argv[]) { MyServer s; return s.run(); }