Link to home
Start Free TrialLog in
Avatar of mitrakis
mitrakisFlag for Germany

asked on

how to program queue (FIFO)?

I have developed a SocketServer for accessing my remote controlled WebCam.
Now I need a queue to administrate access.
Please, can someone post me code for this queue ?

In case a client logs in, connection to SocketServer is established and he can control my WebCam.
Conditions:
- Only the "first" client is allowed to control it (others have to wait until first "hang up")
- After 2 min., connection should be interrupted and next client in list is allowed to control the Cam, and so on...
- elements have to be identified by IP-Adress of client (in case say #4 don't want to wait and disconnects, it has to be removed from list of course)

What I need is simply the queue...! doesn't matter if FIFO or some kind of array...I dunno what's better/easier here.

I've reposted this Q coz there was no feedback at all =:-(

I JUST NEED CODE OF A KIND OF A QUEUE:
Inserting an element, removing an element...where the elements are identified by something like an IP-Adress or another identifier.

If you need more detailed info, let me know.

Best regards
-Stavi-
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

To use the C++ queueu you need to include the <queue.h> include file.  You will need to create a class, structure, or type to store the information you want in each item the queue.  Say that type is called.  QueueItem, you can then create a queue to store items of that type usign

queue<QueueItem> AQueue;
You place an item on the queue using the push() procedure like

AQueue.push(NewItem);

You can test to see if there are any items in the queue with the empty() procedure, like

if (AQueue.empty()) ....

You can access the first item in the queue with the top() procedure like

QueueItem CurrentItem = AQueue.top();

You can remove the first item from the queue with the pop() procedure like

AQueue.pop();

Let me know if you have any questions.
Avatar of mitrakis

ASKER

THX...now I'm on the way home...I'll check back tomorrow and let you know.

Unfortunately, I solved this queue prob by myself (don't worry...you'll be credited) but now I have a "security violation" regarding my JavaApplet.
Maybe you have any experiences in Java ?...then I'll post my prob here tomorrow (I know that this is the wrong topic, but anyway)

Best regards
-Stavi-

BTW:
Why the hell does the system offer me to reject "MWORMLEY'S" proposed answer ?
nietod, any idea ?...is this another nickname of you ?...or just an error in EE's database ?
I don't know anything about java, but it is similar to C++, so I can look it over.  .

I'm not sure what you mean about mwormely's answer.  (since this is your question, you get additional stuff on the page that I don't get.)  Is that what it says for this question?  The message that says the name of the expert that answers is new as of this weekend.  Perhaps they have a bug in it.  If so, that is, if you don't see my name listed in the message on this question, don't accept the answer yet.  Post a 0 point question in the customer service topic area (there is a link at the bottom-right corner of the EE home page).that explains the problem.  Let them know that you are leaving the question open so they can see the problem.  

Just for future reference..
to use the Standard Library's queue,

it's:  #include <queue>
not:   #include <queue.h>

true.  I can never keep that straight.