Sockets Array in C

1

I'm studying in C and I'm creating a program that exchanges messages between pc's in the client / server style. I created an array of sockets and put them in threads.

 int main ()
  {
    pthread_t *servidor = malloc(sizeof(int*)*2);
    pthread_t gui;
    int porta = 5553;

    void *statusConexao;

    //pthread_create(&gui, NULL, iniciaGui,NULL);


      for (int i = 0; i < 2; i++)
    {
    pthread_create (&servidor[i], NULL, AtivarServidor,(void *)(porta+i));

   }
  for(int i = 0; i <= 2; i++)
 {
  pthread_join (servidor[i], &statusConexao);
  printf("retorno e: %d\n",(int)statusConexao);
 }
 }

The goal is that after the connection has been closed on the client side, the function that creates the server on the thread returns 1 when it is called pthread_exit () (within the Enable Server function), then with that return reopen the connection on that port again.

It happens that with the code that I have, the return is only received after all socket connections have been closed, I think it's because the pthread_join function is inside a for, someone has a hint how I can solve this problem?

    
asked by anonymous 24.06.2018 / 23:22

0 answers