Start demo in infinite loop.
This commit is contained in:
parent
6a3bd9c290
commit
3e15f1dc8a
37
demo/main.c
37
demo/main.c
@ -19,27 +19,42 @@
|
||||
|
||||
#include <neocomm.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
int main() {
|
||||
unsigned short port = 0;
|
||||
char connect_address[128];
|
||||
int run = 1;
|
||||
|
||||
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;
|
||||
|
||||
printf("Listening port: ");
|
||||
scanf("%hd", &port);
|
||||
printf("Foreign IP/DNS: ");
|
||||
scanf("%s", &connect_address);
|
||||
printf("Foreign port: ");
|
||||
scanf("%hd", &connect_port);
|
||||
if(argc == 4)
|
||||
{
|
||||
connect_address = argv[2];
|
||||
connect_port = atoi(argv[3]);
|
||||
}
|
||||
|
||||
if(!NeoComm_init(port))
|
||||
{
|
||||
fprintf(stderr, "%s", NeoComm_get_last_error());
|
||||
fprintf(stderr, "%s\n", NeoComm_get_last_error());
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGINT, quit);
|
||||
if(connect_address)
|
||||
NeoComm_connect(connect_address, connect_port);
|
||||
|
||||
while(run) { }
|
||||
|
||||
NeoComm_deinit();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user