I program an online game for two reasons: one, to get to know server / client requests in real time (unlike a regular web browser that is not in real time), and actually get my hands wet in this area, therefore, I can begin to create it correctly.
Anywho, I do this in C ++, and I use winsock to handle basic basic network tests. I obviously want to use framelimiter and have 3D output, and all this at some point, and my main problem is that when I execute the send () or receive () function, the program kindly stands there and waits for an answer . This can lead to 8 fps even with the best internet connection.
Thus, the obvious solution for me is to get the network code out of the main process and start it in its thread. Ideally, I would call “send” in my main process, which would send a pointer to a message to the network stream and then periodically (every frame) to check if the network stream received a response or timeout, or what you have. In an ideal world, I would actually have two or more network streams working at the same time, so that I could say that I launched the chat window and performed background download of part of the armor and still let the player run around right away.
The main problem is that for me this is a new business. I understand the concept of streaming, but I see some serious problems, for example, what happens if two streams try to read and write the same memory address at the same time, etc. I know that methods already exist for processing this type, that I am looking for suggestions on the best way to implement something like this. Basically, I need thread A to be able to start a process on thread B, sending a piece of data, the polling status of a B stream, and then getting a response, like a piece of data., Ideally, without any major glitches. ^ _ ^ I will worry about what actually contains this data, and how to process dropped packets, etc. Later I just need to do this first.
Thanks for any help / advice.
PS: Just thought about it, it might make the question easier. Is there a way to use the Windows event processing system to my advantage? For example, is it possible for thread A to initialize data somewhere, then fire an event in thread B to receive data, and vice versa for thread B to tell thread A that it was done? This will probably solve many of my problems, since I really do not need both threads to be able to work with data at the same time. I just don't know if this is possible between two different threads. (I know that a single thread can create its own messages for an event handler.)