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