Replying to a client over sockets (UDP) from a different process

后端 未结 2 737
名媛妹妹
名媛妹妹 2021-01-27 09:29

I have a server than is a \"command handler\" process. It receives messages over UDP, and delegates the work to do to a different process by communicating to that process throu

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-27 09:54

    You should be testing for the error return, something like

    if((nsfd = socket (AF_INET, SOCK_DGRAM, IPROTO_UDP)) < 0} {
        perror("at socket open");
        // I'd call exit here, probably
    }
    if(sendto(nsfd, buff, bread, 0, &addr, sizeof(addr) < 0){
        perror("At sendto");
    }
    

    There's a nice tutorial example here.

提交回复
热议问题