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 ..

    1 answer 1

    In normal form, it should look like

    1. The main thread is the handler of your form.
    2. additional thread - message queue handler (incoming)
    3. additional thread - message queue handler (outgoing)

    Point 2 and 3 are repeated n times for parallelization on multi-core processor systems. An additional stream is created, which will track the "clogged" queues and transfer customers from crowded queues to more free ones, but it is too early for you to touch it; create an application in 2 streams, paragraph 2 and 3 will be merged into this stream.

    • .. so in some file to write the function of extracting messages from the queue? and the processing function of each client .. - AnnaHatiko