C, socket programming: Connecting multiple clients to server using select()

后端 未结 5 1942
有刺的猬
有刺的猬 2021-02-02 00:23

I\'m trying to make a server that can be connected to by multiple clients. Here\'s my code so far:

Client:

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

  struct so         


        
5条回答
  •  梦毁少年i
    2021-02-02 01:05

    Two issues in your code:

    • You should do recv(i, ...) instead of recv(clientsock[i], ...)

    • After that you do not check if recv() failed, and therefore printf() prints out the uninitialised buffer message, hence the garbage in the output

提交回复
热议问题