I make a program to send / receive data to the server, and decided to make it asynchronous. I read a lot of forums, but I still don’t quite understand the sequence of actions.

Look here - I am doing a thread with the CreateEvent (...) command. Next, I have to create a socket, or is it still a "thread" (thread [0] = CreateThread (...)) in which to create a socket? And if I want to make a second thread, then I will need to create a second thread [1] = CreateThread (...)? Or another event?

Plus, sockets have their own WSACreateEvent, and in the internet they saw that they create an Event, then Thread, then in this Thread they create a WSACreateEvent ... The question is - for what?
Can you explain? :)

    1 answer 1

    CreateEvent does not create a stream. This function creates an event to which a thread can react and synchronize itself with other threads. Those. This is something like a data locker.

    Further, you can create a socket both in the thread and outside it. If you need to access the socket in several threads, then take it out of the thread. If only one thread will work with it, then it makes sense to hide the socket inside. To create a second thread, you need to call CreateThread again.

    WSACreateEvent - used for asynchronous work with sockets. Those. a program can be like a single-threaded one, but at certain events (for example, an asynchronous socket receives a message), the program function called with this event is called.

    In general, I advise you to read more about sockets, threads, and events. The internet is full of information. It is better to search for answers not on the forums, but in msdn or some self-instruction manuals and online manuals.

    • The fact of the matter is that msdn almost know it already by heart, but for some reason I can’t collect everything into the big picture. - DizzWebS
    • And yes, thanks a lot, it has become more clear. By the way, this is my question, but I explained there more, which is not clear: borland.xportal.ru/forum/viewtopic.php?p=120396#120396 That is, it turns out, I can create an Event, immediately create Tread1 and into it stuff a socket that works throughout the program, and create a thread2 with a socket to send-receive a message? Or create an Event, stuff a socket, and separately with the thread to create / delete a second socket? - DizzWebS
    • And also by thread - I do not quite understand that it is necessary to transfer it to the fourth parameter. In the internet, everyone transmits some kind of structure. What is she for? - DizzWebS
    • Although on the last question - I see that some just 0 transmit. - DizzWebS
    • Read the documentation, or remember, you know by heart msdn .. - Vitaly Dyatlov