Re: control over keyboard and sockets (like unix's select)
From: GuitarBill (GuitarBill_at_cox_dot_net)
Date: 08/10/04
- Next message: Dave: "Re: command line tool to convert VC project files to Makefile"
- Previous message: Boris Zakharin: "Using LockFileEx with CancelIo"
- In reply to: hartman: "control over keyboard and sockets (like unix's select)"
- Next in thread: Alexander Grigoriev: "Re: control over keyboard and sockets (like unix's select)"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 9 Aug 2004 17:49:08 -0700
According to the docs, WSACreateEvent() creates a "manual reset" event,
which means once its set it stays set unless you reset it manually (ie use
WSAResetEvent()).
Bill
"hartman" <hartman@mixmail.com> wrote in message
news:411802b0$1_1@filemon2.isp.telecable.es...
> Hello,
>
> I have a server (a console type application) that listen clients through a
> socket and users type commands in server through keyboard. So my server
> execution it's a loop where application should be blocked waiting for data
> in the socket or keys pressed by the user.
>
> Searching in newsgroups and google, I found the WaitForMultipleObjects
> function and write a first version of the possible solution, but when the
> program starts it enters in an infinite loop showing "I'm the keyboard"
> indefinitely, it's like always a key had been pressed. If I remove the
> keyboard and wait only for the socket, it works the first time, but
> following iterations shows "I'm the socket".
>
> I would like to see an example of how could I manage sockets and keyboard
> like Unix's "select" function. Below I show the source code used.
>
> thanks in advance
>
> Javier
>
>
> /* data arrives to socket */
> WSAEVENT datosSocketEvnt;
> // keyboard event
> HANDLE keyboardEvnt;
> /* array of events */
> HANDLE myEvents[2];
>
> // creates new event for socket
> datosSocketEvnt = WSACreateEvent();
> WSAEventSelect(serverSocket, datosSocketEvnt, FD_READ);
> myEvents[0] = datosSocketEvnt;
>
> keyboardEvnt = GetStdHandle(STD_INPUT_HANDLE);
> myEvents[1] = keyboardEvnt;
>
> while (key != 'E')
> switch (WaitForMultipleObjects(2, myEvents, FALSE, INFINITE)) {
> case WAIT_OBJECT_0:
> fprintf(stderr, "I'm the socket\n");
>
> case WAIT_OBJECT_0 + 1:
> fprintf(stderr,"I'm the keyboard\n");
> break;
> }
>
> P.S: Source code compiles OK, I translate the variable names to English
for
> a best understanding of code, sorry for my very bad English
>
>
>
- Next message: Dave: "Re: command line tool to convert VC project files to Makefile"
- Previous message: Boris Zakharin: "Using LockFileEx with CancelIo"
- In reply to: hartman: "control over keyboard and sockets (like unix's select)"
- Next in thread: Alexander Grigoriev: "Re: control over keyboard and sockets (like unix's select)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|