How can I implement a Winsock Thread?
Im working on an experimental server/client game and I was wondering how can I switch my winsock tcp/ip code to a thread, instead of in the main window itself? I have read an article on threads here on gamedev. But I basically dont know how to pass the info from the thread to my main loop.
Example.
Player 1 said "text"
"text" is send to server
server sends "text" to all logged users.
Player 2 gets "text" on separate thread
"text" is send to ????
Threads in a process share the same memory space.
i.e. Use a global.
You could also create a special user message and send a message to thread with a pointer as the param
i.e. Use a global.
You could also create a special user message and send a message to thread with a pointer as the param
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I was thinking of a solution whereby you call the main thread with a user message notifying it that a message has arrived as suggested by magmai :p
or you can poll a global variable.
when you share a variable between two threads (read/write of data/flags/pointers), you should use mutex''s - so that the two threads don''t try to access the variable at the same time.
Wyzfen
or you can poll a global variable.
when you share a variable between two threads (read/write of data/flags/pointers), you should use mutex''s - so that the two threads don''t try to access the variable at the same time.
Wyzfen
I''ve done chat servers via the following:
* give each connection a send queue (or even better a deque)
* if one connection wants to send stuff to another it gets appended to the queue
* the socket-handler code is in charge of checking its own queue and dequing/sending messages when appropriate
Basically, the connection data list is global somehow... or you could make the connection list a static member of the connection class. I actually have a fairly generic set of server code written but it only works using IOCP right now and it needs fleshing out before I''d make it available.
* give each connection a send queue (or even better a deque)
* if one connection wants to send stuff to another it gets appended to the queue
* the socket-handler code is in charge of checking its own queue and dequing/sending messages when appropriate
Basically, the connection data list is global somehow... or you could make the connection list a static member of the connection class. I actually have a fairly generic set of server code written but it only works using IOCP right now and it needs fleshing out before I''d make it available.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement