Создание приложений с использованием многопоточности при обработки запросов клиентов, страница 6

                    SendInfoGlobal();

                    if (isDead(usercd))

                    {

                          std::string request = "POST / HTTP/1.0\r\nContent-Length: 1024\r\nContent-Type: application/octet-stream\r\n\r\n";

                          int iterator = 0;

                          char msg[1024];

                          for (; iterator < request.length(); iterator++)

                                 msg[iterator] = request[iterator];

                          msg[iterator] = (char)9 + '0';

                                 iterator++;

                          msg[iterator] = 0;

                          send(clientList[usercd - 1], msg, 1024, 0);

                          char deadMess[256];

                          sprintf(deadMess, "Player%d is dead", usercd);

                          PrintMessage(deadMess);

                          //delete(deadMess);

                          Sleep(INFINITE);

                    }

                    else

                    {

                          if (totalCount - deadCount <= 1)

                          {

                                 //buffer[0] = (char)8 + '0';

                                 std::string request = "POST / HTTP/1.0\r\nContent-Length: 1024\r\nContent-Type: application/octet-stream\r\n\r\n";

                                 int iterator = 0;

                                 char msg[1024];

                                 for (; iterator < request.length(); iterator++)

                                       msg[iterator] = request[iterator];

                                 msg[iterator] = (char)8 + '0';

                                 iterator++;

                                 msg[iterator] = 0;

                                 send(clientList[usercd - 1], msg, 1024, 0);

                                 char winnerMess[256];

                                 sprintf(winnerMess, "Player%d Winner\n", usercd);

                                 PrintMessage(winnerMess);

                                 //delete(winnerMess);

                                 Sleep(INFINITE);

                          }

                    }

             }

       }

}

VOID CALLBACK APCProc(ULONG_PTR dwParam)

{

}

void RunServer()

{

       messageBoxSemaphore = CreateSemaphore(NULL, 1, 1, NULL);

       serverSocket=socket(AF_INET,SOCK_STREAM,0);

       if(serverSocket==INVALID_SOCKET)

       {

             MessageBox(0, (LPCSTR) "socket error", (LPCSTR)"Error", MB_OK);

       }

       SOCKADDR_IN sa;

       sa.sin_family=AF_INET;

       sa.sin_port=htons(561);

       sa.sin_addr.S_un.S_addr=INADDR_ANY;

       //

       if(bind(serverSocket,(sockaddr*) &sa, sizeof(sa)))

       {

             MessageBox(0, (LPCSTR) "OOPS! Bind error", (LPCSTR)"Error", MB_OK);

             return;

       }

       if(listen(serverSocket,4))

       {

             MessageBox(0, (LPCSTR) "listen error", (LPCSTR)"Error", MB_OK);

             return;

       }

       HANDLE thrArr[4];

       SOCKADDR_IN csa;

       int csa_size=sizeof(csa);

       char message[256];

       sprintf(message, "Server started\r\n");

       SendMessage(messBox, EM_SETSEL, -1, -1);

       SendMessage(messBox, EM_REPLACESEL, TRUE, (LPARAM)message);

       int i = 0;

       //totalCount = 1;

       while(cSock=accept(serverSocket,(sockaddr*) &csa,&csa_size))

       {

             if (playerCount < totalCount)

             {

                    CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RunRecv, (LPVOID)cSock, NULL, NULL);

                    sprintf(message, "Player%d connected\r\n", playerCount + 1);

                    SendMessage(messBox, EM_SETSEL, -1, -1);

                    SendMessage(messBox, EM_REPLACESEL, TRUE, (LPARAM)message);

             }

       }

}

#endif

Вывод: Разработали программное обеспечение, реализующее передачу данных между компьютерами, с использованием классов и объектов в инструментальной среде для передачи информации.