TCP client-server SIGPIPE

前端 未结 2 750
刺人心
刺人心 2021-01-19 10:22

I am designing and testing a client server program based on TCP sockets(Internet domain). Currently , I am testing it on my local machine and not able to understand the foll

2条回答
  •  执念已碎
    2021-01-19 11:15

    SIGPIPE is sent when you try to write to an unconnected pipe/socket. Installing a handler for the signal will make send() return an error instead.

    signal(SIGPIPE, SIG_IGN);
    

    Alternatively, you can disable SIGPIPE for a socket:

    int n = 1;
    setsockopt(thesocket, SOL_SOCKET, SO_NOSIGPIPE, &n, sizeof(n));
    

    Also, the data amounts you're mentioning are not very high. Likely there's a bug somewhere that causes your connection to close unexpectedly, giving a SIGPIPE.

提交回复
热议问题