使用 Fork() 在 C 中实现 TCP 并发 Client/Server

TCP Concurrent Client/Server in C by using Fork()

asdfg askjhgkasdhj gfskjd;hdgfk ;jasgdjkf hasdjkghf asdjkf hasdjkfgh klasdhdf jkasdjkf hdjksahf jklhdjkf asjkdhdf jkdlf ajsdhf jklashdf jaksdf hkjlasdjklf hasdhdf kdf kjlasdhdf hkjadf ljkdf adf kjahdkf adf kjashdfhkjlsasdf

 else {
        printf("[-]Invalid command\n");
      }
    }

    bzero(buffer, SIZE);
  }

}

您有几个问题:

-Don't close sockfd, this will prevent further connections from being accepted on the server
-The socket should be closed on both ends in the quit case
-The fact that the client side uses a random port is fine.  Nothing needs to be changed there