https.. 2025. 6. 25. 09:03
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "env_all.h"
#include "client.h"
#include "libatcomm.h"
#include "libptcomm.h"
#include "neo_profile.h"
#include "pt_header.h"

int connect_host(char *address, int conn_port, int connect_timeout);
int sosend(int sock, char *buffer, int len);

int main(int argc, char* argv[])
{
    int fdsock;
    char buffer[8096];

    if (argc != 2) {
        printf("사용법: ./client [id]\n");
        return 0;
    }

    // 소켓 연결
    fdsock = connect_host("127.0.0.1", 13021, 3);
    if (fdsock < 0) {
        _ST_LOG("MCI Connect Fail... %d\n", fdsock);
        return -1;
    }

    // 실시간 등록 메시지 전송
    memset(buffer, 0, sizeof(buffer));
    sprintf(buffer, "00000224A00SUBSET_KYA202506161558591230001M01.0MTS203248169111010112252149KIMYUNA                                           000000000000000000010  R000001000005");
    sosend(fdsock, buffer, strlen(buffer));
    _ST_LOG("실시간 등록 메시지 전송 완료");

    // 파일 읽어서 전송
    FILE *fp = fopen("scs_dm_pcinetd", "rb");
    if (!fp) {
        perror("파일 열기 실패");
        close(fdsock);
        return -1;
    }

    char file_buf[4096] = {0};
    size_t read_len = fread(file_buf, 1, sizeof(file_buf), fp);
    fclose(fp);

    if (read_len > 0) {
        sosend(fdsock, file_buf, read_len);
        _ST_LOG("scs_dm_pcinetd 파일 %lu 바이트 전송 완료", read_len);
    } else {
        _ST_LOG("파일 읽기 실패 또는 비어 있음");
    }

    close(fdsock);
    return 0;
}