aboutsummaryrefslogtreecommitdiff
path: root/client/main.cpp
blob: 5c261075c942c93db538ca2eb86d824f31aded90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}