Help in creating a WSAEventSelect model winsock client application 
Author Message
 Help in creating a WSAEventSelect model winsock client application

Hello,

I'd like to create a client winsock application using sockets based on the
WSAEventSelect model. This application may require the creation of more than
one socket at any time based on certain circumstances. I would like not to
have to create more that one thread that executes the usual loop containing
the WSAWaitForMultipleEvents call.

The problem I'm facing is that created the first socket, once the thread is
put on wait on the WSAWaitForMultipleEvents call I will have a chance to
create the other needed sockets only INSIDE the loop containing the
WSAWaitForMultipleEvents call (I create a first socket and create the others
if and when needed). This however will only be possible when the thread
waiting on WSAWaitForMultipleEvents is "awakened" by a network event for the
first socket. Unfortunately this network event could happen sometime after
my need for creating another socket araises (in fact I have no certainty
that the thread will ever be awakened to have a chance to create a second
socket). I thought it could be possible to generate a "custom" network event
to "awaken" the thread so that it could create the new socket but
unfortunately this isn't possible. The only solution I came up with is the
creation of two sockets, one not using the WSAEventSelect model (and handled
by a different thread) and employed just to awaken another (this one based
on the WSAEventSelect model) inside the loop which is responsible for
creating the "WSAEventSelect model" sockets that will do the REAL data
exchange. Honestly I'm not satisfied by this solution and I'd appreciate if
anyone could suggest a better solution?

Regards,
Bob Rock



Mon, 10 Jan 2005 06:06:27 GMT  
 Help in creating a WSAEventSelect model winsock client application

Quote:

> Hello,

> I'd like to create a client winsock application using sockets based on the
> WSAEventSelect model. This application may require the creation of more than
> one socket at any time based on certain circumstances. I would like not to
> have to create more that one thread that executes the usual loop containing
> the WSAWaitForMultipleEvents call.

> The problem I'm facing is that created the first socket, once the thread is
> put on wait on the WSAWaitForMultipleEvents call I will have a chance to
> create the other needed sockets only INSIDE the loop containing the
> WSAWaitForMultipleEvents call (I create a first socket and create the others
> if and when needed). This however will only be possible when the thread
> waiting on WSAWaitForMultipleEvents is "awakened" by a network event for the
> first socket. Unfortunately this network event could happen sometime after
> my need for creating another socket araises (in fact I have no certainty
> that the thread will ever be awakened to have a chance to create a second
> socket). I thought it could be possible to generate a "custom" network event
> to "awaken" the thread so that it could create the new socket but
> unfortunately this isn't possible. The only solution I came up with is the
> creation of two sockets, one not using the WSAEventSelect model (and handled
> by a different thread) and employed just to awaken another (this one based
> on the WSAEventSelect model) inside the loop which is responsible for
> creating the "WSAEventSelect model" sockets that will do the REAL data
> exchange. Honestly I'm not satisfied by this solution and I'd appreciate if
> anyone could suggest a better solution?

> Regards,
> Bob Rock

The scalable solution is I/O completion ports.  Check out Felix Kasza's
Sockets & IOCPs sample at http://www.mvps.org/win32/

--
Scott McPhillips [VC++ MVP]



Mon, 10 Jan 2005 06:53:29 GMT  
 Help in creating a WSAEventSelect model winsock client application

Quote:

> Hello,

> I'd like to create a client winsock application using sockets based on the
> WSAEventSelect model. This application may require the creation of more than
> one socket at any time based on certain circumstances. I would like not to
> have to create more that one thread that executes the usual loop containing
> the WSAWaitForMultipleEvents call.

> The problem I'm facing is that created the first socket, once the thread is
> put on wait on the WSAWaitForMultipleEvents call I will have a chance to
> create the other needed sockets only INSIDE the loop containing the
> WSAWaitForMultipleEvents call (I create a first socket and create the others
> if and when needed). This however will only be possible when the thread
> waiting on WSAWaitForMultipleEvents is "awakened" by a network event for the
> first socket. Unfortunately this network event could happen sometime after
> my need for creating another socket araises (in fact I have no certainty
> that the thread will ever be awakened to have a chance to create a second
> socket). I thought it could be possible to generate a "custom" network event
> to "awaken" the thread so that it could create the new socket but
> unfortunately this isn't possible. The only solution I came up with is the
> creation of two sockets, one not using the WSAEventSelect model (and handled
> by a different thread) and employed just to awaken another (this one based
> on the WSAEventSelect model) inside the loop which is responsible for
> creating the "WSAEventSelect model" sockets that will do the REAL data
> exchange. Honestly I'm not satisfied by this solution and I'd appreciate if
> anyone could suggest a better solution?

> Regards,
> Bob Rock

You don't have to use WSAWaitForMultipleEvents().

Create an additional event and wait on it as well as on any sockets that
you're using with WaitForMultipleEvents().

Somewhere in your program you decide that you need an new socket; at
that point create and connect the socket and use WSAEventSelect() to
attach an event. Add that event to the array of events on which your
main loop is waiting and then use SetEvent() to "wake up" the main loop.
In can immediately go back to WaitForMultipleEvent() but this time it's
waiting on one more event than before.

Norm



Mon, 10 Jan 2005 12:00:25 GMT  
 Help in creating a WSAEventSelect model winsock client application

Quote:

> The scalable solution is I/O completion ports.  Check out Felix Kasza's
> Sockets & IOCPs sample at http://www.mvps.org/win32/

> --
> Scott McPhillips [VC++ MVP]

Completion ports are only supported by NT, 2000 and probably XP. I'd like to
utilize my code also on 9x and ME machines.

Regards,
Bob Rock



Mon, 10 Jan 2005 17:33:31 GMT  
 Help in creating a WSAEventSelect model winsock client application

Quote:
> You don't have to use WSAWaitForMultipleEvents().

> Create an additional event and wait on it as well as on any sockets that
> you're using with WaitForMultipleEvents().

> Somewhere in your program you decide that you need an new socket; at
> that point create and connect the socket and use WSAEventSelect() to
> attach an event. Add that event to the array of events on which your
> main loop is waiting and then use SetEvent() to "wake up" the main loop.
> In can immediately go back to WaitForMultipleEvent() but this time it's
> waiting on one more event than before.

> Norm

WaitForMultipleEvents???? You mean WaitForMultipleObjects I suppose. Will a
thread waiting on it be awaked even by a network event? Thx.

Regards,
Bob Rock



Mon, 10 Jan 2005 17:42:20 GMT  
 Help in creating a WSAEventSelect model winsock client application

Quote:
> WaitForMultipleEvents???? You mean WaitForMultipleObjects I suppose. Will
a
> thread waiting on it be awaked even by a network event? Thx.

In a word, yes :).

From WSACreateEvent documentation (Platform SDK): "Windows Sockets 2 event
objects are system objects in Windows environments."

So you can create the event objects with CreateEvent() if you wish (also
noted in docs). Either way, you can wait on them using
WaitForMultipleObjects(), along with any other waitable objects.

Alex



Tue, 11 Jan 2005 00:03:48 GMT  
 Help in creating a WSAEventSelect model winsock client application
Though not as efficient, it may be simpler to specify a timeout value to
WSAWaitForMultipleEvents (say, 200ms) and on each timeout, do the additional
processing you need.

- Steve


Quote:
> Hello,

> I'd like to create a client winsock application using sockets based on the
> WSAEventSelect model. This application may require the creation of more
than
> one socket at any time based on certain circumstances. I would like not to
> have to create more that one thread that executes the usual loop
containing
> the WSAWaitForMultipleEvents call.

> The problem I'm facing is that created the first socket, once the thread
is
> put on wait on the WSAWaitForMultipleEvents call I will have a chance to
> create the other needed sockets only INSIDE the loop containing the
> WSAWaitForMultipleEvents call (I create a first socket and create the
others
> if and when needed). This however will only be possible when the thread
> waiting on WSAWaitForMultipleEvents is "awakened" by a network event for
the
> first socket. Unfortunately this network event could happen sometime after
> my need for creating another socket araises (in fact I have no certainty
> that the thread will ever be awakened to have a chance to create a second
> socket). I thought it could be possible to generate a "custom" network
event
> to "awaken" the thread so that it could create the new socket but
> unfortunately this isn't possible. The only solution I came up with is the
> creation of two sockets, one not using the WSAEventSelect model (and
handled
> by a different thread) and employed just to awaken another (this one based
> on the WSAEventSelect model) inside the loop which is responsible for
> creating the "WSAEventSelect model" sockets that will do the REAL data
> exchange. Honestly I'm not satisfied by this solution and I'd appreciate
if
> anyone could suggest a better solution?

> Regards,
> Bob Rock



Tue, 11 Jan 2005 00:33:55 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Threading model for the client application

2. Threading model for the MFC Client Application

3. a Question when Create Service application with Winsock supported

4. a Question when Create Service application with Winsock supported

5. Creating the MFC Rich Client Application ** OLD Newbie**

6. Has anyone succeded: Walkthrough: Creating a Rich Client Application with MFC

7. Has anyone succeded: Walkthrough: Creating a Rich Client Application with MFC

8. Winsock Winsock Winsock !!!

9. Looking for sample sockets client/server chat model

10. Apartment Model Threading and Client Behavior

11. Apartment Model Threading and Client Behavior

12. Smart Client Deployable Model

 

 
Powered by phpBB® Forum Software