Simultaneously wait for input and process incoming packets
by Killer7 · in Torque Game Engine · 08/24/2006 (7:41 am) · 3 replies
Hello,
I am developing a simple chat client.
I'd like to know how (on the client) I can simultaneously wait for input from the user and process incoming packets from other clients at the same time.
Currently I am using std::getline(std::cin,str);.....
As you must know this is a blocking function, so I am waiting here and thus cannot do the processing of packets from elsewhere until I write something on the client myself (i.e. it doesn't get to checkIncomingPackets() and
processConnections()).
Is there some way of threading in TNL, or can it be done using Event Handling methods in C++?
Thanks in advance.
I am developing a simple chat client.
I'd like to know how (on the client) I can simultaneously wait for input from the user and process incoming packets from other clients at the same time.
Currently I am using std::getline(std::cin,str);.....
As you must know this is a blocking function, so I am waiting here and thus cannot do the processing of packets from elsewhere until I write something on the client myself (i.e. it doesn't get to checkIncomingPackets() and
processConnections()).
Is there some way of threading in TNL, or can it be done using Event Handling methods in C++?
Thanks in advance.
#2
Polling and Stdin both have significant problems.
- Unfortunately i'm not familiar with TNL,
but it seems like you're lacking the whole event model.
In windows this usually manifests as WindowProc() and associated calls.
08/29/2006 (11:36 am)
Event handling is the way this stuff is done on modern systems.Polling and Stdin both have significant problems.
- Unfortunately i'm not familiar with TNL,
but it seems like you're lacking the whole event model.
In windows this usually manifests as WindowProc() and associated calls.
#3
Thanks for the help. Yes, I needed some sort of event-handling or threads. Ive got the general idea now. Hopefully this wont be a problem.
Thanks again fellows.
09/05/2006 (12:32 am)
Hello,Thanks for the help. Yes, I needed some sort of event-handling or threads. Ive got the general idea now. Hopefully this wont be a problem.
Thanks again fellows.
Torque Owner Shyam "Doggan" Guthikonda
I am not sure of the 'recommended' or 'ideal' solution, but since no one has replied, I will shoot off some ideas.
- Threads are an option. I have never used the thread implementations provided directly through TNL (this is on the TODO list for my project), but there is support (see: tnlThread.h). Or you can always roll your own thread implementation, or use a 3rd party library (i.e. OpenThreads). As always, with threads come a slew of advantages and disadvantages. Depending on your application, you may not want to deal with this.
- You can always use simple 'polling' of the key states. Store this internally as an input buffer, which can be displayed to the console. When the user hits "Enter", send the current buffer off via your RPC call (or whatever method you're using), then clear the buffer. This method requires you to have the infinite 'game loop'. So your packet processing calls will be invoked once per cycle, as desired.