boardYP.c 2 KB
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>

#define Port 23

int Sockfd;

typedef struct {
	char filename[256];
	char result_filename[256];
	char sender[30];
	char pwd[256];
	int pass;
} Info;

void Receivedone()
{
	close(Sockfd);
	printf("\n Program done\n");

	exit(0);
}

main(int argc, char* argv[])
{
	int newSockfd, hostAddrLen, n;
	struct sockaddr_in hostAddr, boardAddr;
	Info info;

	signal(SIGINT, Receivedone); // 종료 signal

	if((Sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket");
		exit(1);
	}

	bzero((char*)&boardAddr, sizeof(boardAddr));
	boardAddr.sin_family = PF_INET;
	boardAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	boardAddr.sin_port = htons(Port);

	if(bind(Sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
		perror("bind");
		exit(1);
	}

	listen(Sockfd, 5);
	
	printf("\nReceive waiting\n\n");

	hostAddrLen = sizeof(hostAddr);

	while(1) {
		info.pass = 0;
		char path[256] = "~/Vitis-AI/vitis_ai_library/samples/yolov3/test_jpeg_yolov3 yolov3_bdd ";
		char scp[256] = "scp ";
		newSockfd = accept(Sockfd, (struct sockaddr*)&hostAddr, &hostAddrLen);
		if(newSockfd < 0) {
			perror("accept");
			exit(1);
		}
		if((n = read(newSockfd, (char*)&info, sizeof(info))) < 0) {
			perror("read");
			exit(1);
		}

		printf("Start yolo : %s\n", info.filename);
		strcat(path, info.filename);

		if(system(path)) { // yolo 실행
			perror("system");
			exit(1);
		}
		// scp 명령어 만들기
		strcat(scp, info.result_filename);
		strcat(scp, " ");
		strcat(scp, info.sender);
		strcat(scp, ":");
		strcat(scp, info.pwd);
		printf("%s\n", scp);
		
		if(system(scp)) { // scp 명령어 실행
			perror("system");
			exit(1); 
		}

		info.pass = 1;
			
		if(write(newSockfd, (char*)&info, sizeof(info)) < 0) {
			perror("write");
			exit(1);
		}
		
		printf("\nSuccess\n=========================================================\n\n");
		close(newSockfd);
	}
}