Hello.
I did a client-server application in the console, now I need to redo it with a graphical interface. I created a project Windows Application Form. Just do not understand yet where to write the main code of the program. For example, to start a server, I pulled a button onto a form — a handler on it — responsible for initializing Winsock, opening a socket, associating with a local address, waiting for connections. And then the console project is retrieving from the message queue
Tell me please!
I tried to load the server's form in Load to initialize the Winsock library, create a socket, bind it to the local address, work fine, then go through the console project — you need a loop to process the retrieval of messages from the queue.
SOCKET accepted_socket = INVALID_SOCKET; while(true) { if ((accepted_socket = accept(server_listen_socket, NULL, NULL)) == INVALID_SOCKET) { Form1->richTextBox1->Text += "\nОшибка при извлечении сообщения из очереди...\n"; closesocket(server_listen_socket); WSACleanup(); break; } else { Form1->richTextBox1->Text += "\nСоздан отдельный поток для нового клиента...\n"; } }
I tried forms in Load
- the server does not even start ... Where to write this code - I just can’t understand it ..