다중 PIPE 생성 질문 입니다

croae의 이미지

fork 로 부모와 자식간 IPC 를 위해 파이프를 사용했습니다.

부모가 받은 파일을 자식에게 파이프로 넘겨주고 자식은 받은 파일을 다른 TCP 소켓으로 넘겨주도록이요

그런데 이게 단일 접속만 허용이 되더군요.

최소 2개 이상의 TCP 리시버와 다중 커넥션이 성사가 되어야 하는데 하나의 커넥션만 허용합니다.

알아보니 PIPE는 포크 처럼 복제가 안된다고 하더군요

포크하기전에 파이프 생성 해봤고 포크 한다음에 파이프를 생성해봤는데 둘다 안되더군요..

파이프에 사용된 배열은 1차원 배열을 썼습니다 int pipe (pd[2]);

여러 TCP 리시버와 커넥션을 하기위해서는 어떻게 해야 할까요?

주요 코드만 올려봅니다

int main(int argc,char *argv[]) {

pid_t pid;


int sh1[2];



int str_len2;


long imsi;


bzero((char *)&server,sizeof(server));

server.sin_family=AF_INET;                      /* TCP SOCKET 전용 */
server.sin_port=htons(5565);                    /* TCP SOCKET 전용 */
server.sin_addr.s_addr=htonl(INADDR_ANY);       /* TCP SOCKET 전용 */

if((recv_udpsock= socket(PF_INET, SOCK_DGRAM,0)) < 0)
    error_handling("socket()error");            /*  UDP생성 */    

bzero(&udp_addr, sizeof(udp_addr));
udp_addr.sin_family = AF_INET;                  /*  UDP SOCKET  */
udp_addr.sin_addr.s_addr=htonl(INADDR_ANY);     /*  UDP SOCKET  */
udp_addr.sin_port=htons(atoi(argv[2]));         /*  UDP SOCKET  */

if(bind(serv_sock,(struct sockaddr *)&server,sizeof(server)) < 0)
{
    printf("bind error\n");
    exit(0);
}

if(bind(recv_udpsock, (struct sockaddr*) &udp_addr, sizeof(udp_addr)) < 0)
    error_handling("bind() error");


listen(serv_sock,5);

pipe(sh1);


while(1)
{ 
    client_len=sizeof(client);
    for_foksd=accept(serv_sock,(struct sockaddr *)&client,&client_len);

pid = fork();


if ( pid > 0)                   /* 부모님 영역 */
{       

    puts("connection make\n");
    close(for_foksd);


    while(1)                            /* UDP sender 로부터 파일 수신 */
    {
        recvfrom(recv_udpsock, buf, MAXSIZE, 0, (struct sockaddr*)&udp_addr,&addr_size);

        write(sh1[1],buf,MAXSIZE);  

    }
    close(recv_udpsock);
    continue;
}
else
{
    close(serv_sock);


    printf("여기서부터는 TCP \n");



    while(read(sh1[0], buf,MAXSIZE)) /* 부모로부터 받은 파일을 TCP receiver에게 전송 */
    {
        send(for_foksd,buf,MAXSIZE,0);
        printf("file send ok\n");
    }       
    puts("Connection close");
    close(for_foksd);
    exit(0);
}
return 0;
}

}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.