Start demo in infinite loop.

This commit is contained in:
Nicolás Ortega Froysa 2017-11-05 17:27:05 +01:00
parent 6a3bd9c290
commit 3e15f1dc8a
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF

View File

@ -19,27 +19,42 @@
#include <neocomm.h> #include <neocomm.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
int main() { int run = 1;
unsigned short port = 0;
char connect_address[128]; void quit(int sig) {
puts("\nInterrupt signal received.");
run = 0;
}
int main(int argc, char *argv[]) {
if(argc != 2 && argc != 4)
{
printf("Usage: %s <local_port> [<foreign_address> <foreign_port>]\n", argv[0]);
return 1;
}
unsigned short port = atoi(argv[1]);
char *connect_address = NULL;
unsigned short connect_port = 0; unsigned short connect_port = 0;
if(argc == 4)
printf("Listening port: "); {
scanf("%hd", &port); connect_address = argv[2];
printf("Foreign IP/DNS: "); connect_port = atoi(argv[3]);
scanf("%s", &connect_address); }
printf("Foreign port: ");
scanf("%hd", &connect_port);
if(!NeoComm_init(port)) if(!NeoComm_init(port))
{ {
fprintf(stderr, "%s", NeoComm_get_last_error()); fprintf(stderr, "%s\n", NeoComm_get_last_error());
return 1; return 1;
} }
signal(SIGINT, quit);
if(connect_address)
NeoComm_connect(connect_address, connect_port); NeoComm_connect(connect_address, connect_port);
while(run) { }
NeoComm_deinit(); NeoComm_deinit();
return 0; return 0;
} }