aboutsummaryrefslogtreecommitdiff
path: root/client/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.cpp')
-rw-r--r--client/main.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/main.cpp b/client/main.cpp
new file mode 100644
index 0000000..5c26107
--- /dev/null
+++ b/client/main.cpp
@@ -0,0 +1,38 @@
+#include <cstdio>
+#include <cstdlib>
+#include <cstdint>
+#include <exception>
+
+#include "rl.h"
+#include "sock.h"
+
+PBSocket* sock;
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ printf("usage: %s addr [port]\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ // parse arguments
+ char* addr = argv[1];
+ uint16_t port = 9191;
+ if (argc >= 3) port = atoi(argv[2]);
+
+ sock = new PBSocket(addr, port);
+ try {
+ // connect to TCP socket (automatically spawns thread)
+ sock->sock_connect();
+ } catch (const std::exception& e) {
+ printf("error: %s\n", e.what());
+ return EXIT_FAILURE;
+ }
+
+ // enter main CLI (using GNU readline for comfyness)
+ int ret = cli_main();
+
+ delete sock;
+
+ return ret;
+}
+