RE: socket communication: socket doesn't connect
- From: Ananya <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Apr 2007 19:00:02 -0700
Thanks for your reply. I also was reading your reply to the the previous
answer, where you say:
Winsock offers 6 distinct socket programming models:
- blocking
- non-blocking via select
- non-blocking via events (WSAEventSelect)
- async via windows messages (WSAAsyncSelect)
- overlapped via completion routine
- overlapped via events
= overlapped using I/O Completion Port (IOCP)
(the IOCP model is achieved via overlapped events associated with
the IOCP)
I understand that for me you are suggesting the model:
non-blocking via events (WSAEventSelect).
I am a complete beginner in socket programming and in using threads. Could
you please explain a little more how to do this and how to manage threads, or
could you give me a reference of a tutorial or a book?
Thanks a lot! It is very important for me to find a solution quickly,
because I want to release my product. I wrote a plugin for Photoshop for
drawing curves, the main program is written in Java and then connected to
Adobe's C++ code.
"Ananya" wrote:
Just so that we have now the whole discussion here, let me transfer the 2.
main replies I received so far here:
1) reply from Tom Serface
You may find this to be a good read:
http://en.wikipedia.org/wiki/Winsock
Tom
2) reply from Alexander Nickolov:
Your server is written in C++. However, what language is your
client in? Java? C#? C++/CLI?
As far as your server code goes, you didn't post where you
accept the listening socket. With blocking socket I/O you
are supposed to spawn a new thread (or process in the original
Unix model) to handle the accepted socket and call accept
again right away. This is a terrible model for a Windows socket
server as it generates a huge amount of threads. I suggest you
investigate the other available socket programming models and
pick a better one for a server. The best scaling model is using
overlapped sockets with an I/O Completion Port (IOCP). It
is also the most complex to program. As a compromise I'd sugest
you use event-based non-blocking model via WSAEventSelect
and spawn a new thread for every 63 sockets. Combined with
a bit of thread management this should do well for a medium load
server. (The 63 comes from the limit of 64 handles you can
simultaneously wait on via WatForMultipleObjects. You need
one slot for a thread termination event, thus you have 63 slots
open for socket events. Fewer if you need additional maintenance
handles to wait for on each thread, like a waitable timer for example.)
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
- Follow-Ups:
- Re: socket communication: socket doesn't connect
- From: Alexander Nickolov
- Re: socket communication: socket doesn't connect
- References:
- socket communication: socket doesn't connect
- From: Ananya
- socket communication: socket doesn't connect
- Prev by Date: Re: validating large number of ip address efficiently
- Next by Date: Re: socket communication: socket doesn't connect
- Previous by thread: socket communication: socket doesn't connect
- Next by thread: Re: socket communication: socket doesn't connect
- Index(es):
Relevant Pages
|