소켓프로그래밍 SEND 관련

hyun1023의 이미지

서버에서 클라이언트로 SEND 로 2048 만큼의 데이터를 보냅니다.

근데 이유를 알수없이 전송이 안돼고 바로 끈겨버립니다. 데이타 크기가 커서 그런건지.. 바이너리로 읽어서 0 도 포함돼서 그런건지 도저히 알수가없네요.. 여기서 생길 문제점은 몰까요..

#define DATA_BUF 2049 입니다.

Necromancer의 이미지

소스를 봐야 알 수 있을꺼 같군요 :x

Written By the Black Knight of Destruction

terzeron의 이미지

오동작한 위치에서 에러 코드를 출력해보시죠.

익명 사용자의 이미지

void start_send(int *data_sock) {

        FILE *fd;
        char openfile[strlen(file_queue[0].path)+strlen(file_queue[0].filename)+4];
        printf("path : %s/%s\n",file_queue[0].path,file_queue[0].filename);
        snprintf(openfile,sizeof(openfile),"%s/%s",file_queue[0].path,file_queue[0].filename);
        fd=fopen(openfile,"rb");
        if(fd==NULL) error_handling("File open error");

        int i;
        int filesize;
        int read_num = 0;
        int send_len = 0;
        int send_num = 0;
        int data_len = 0;
        int count = 0;
        int s0,s1,s2;
        char c0,c1,c2;
        char data_buf[DATA_BUF];
        char out_buf[DATA_BUF];
        memset(data_buf,0x0,DATA_BUF);
        memset(out_buf,0x0,DATA_BUF);


        while(data_len < file_queue[0].filesize) {

                s0=s1=s1=0;
                c0=c1=c2='\0';
                printf("while()\n");
                send_len=0;
                send_num=0;
                memset(data_buf,0x0,DATA_BUF);

                read_num = fread(&data_buf[send_len+3],1,(DATA_BUF-1-3)-send_len,fd);
                s1 = (read_num - 3)%256;
                s2 = (read_num - 3)/256;
                printf("read_num : %d , s1 : %d , s2 : %d\n",read_num,s1,s2);


                snprintf(c0,1,"%d",0);
                snprintf(c1,1,"%d",s1);
                snprintf(c2,1,"%d",s2);
                data_buf[0] = c0;
                data_buf[1] = c1;
                data_buf[2] = c2;
        //      for(send_num=0;send_num<read_num+3;) {
                send_num = send(*data_sock,data_buf,MAX_BUF-1000,0);

                if(send_num == -1) {
                        error_handling("data send error\n");
                }
        //      }

}
hyun1023의 이미지

hyun1023 wrote:
서버에서 클라이언트로 SEND 로 2048 만큼의 데이터를 보냅니다.

근데 이유를 알수없이 전송이 안돼고 바로 끈겨버립니다. 데이타 크기가 커서 그런건지.. 바이너리로 읽어서 0 도 포함돼서 그런건지 도저히 알수가없네요.. 여기서 생길 문제점은 몰까요..

#define DATA_BUF 2049 입니다.

아이고 제가 다른부분에서 실수했네용 ^^; 답벼주신분들 감사합니다