Start demo in infinite loop.
This commit is contained in:
parent
6a3bd9c290
commit
3e15f1dc8a
39
demo/main.c
39
demo/main.c
@ -19,26 +19,41 @@
|
|||||||
|
|
||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
NeoComm_connect(connect_address, connect_port);
|
signal(SIGINT, quit);
|
||||||
|
if(connect_address)
|
||||||
|
NeoComm_connect(connect_address, connect_port);
|
||||||
|
|
||||||
|
while(run) { }
|
||||||
|
|
||||||
NeoComm_deinit();
|
NeoComm_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user