How to not accept a new socket connection?

Hello,

I am using CAsyncSocket for my client/server application, everything works 
fine and I can open as many socket connections as I want, but I would like to 
limit the number of connections (say 10 sockets at any one time). During the 
OnAccept() call of my listen socket, is there something I can do to refuse 
the connection, or maybe some other way outside of OnAccept(). Once my open 
socket count goes back below my set limit, I would like to start accepting 
connections again until the limit is maxed out again.

FYI: I've tried to not call Accept() from within OnAccept(), but the client 
side still gets a connection made. I've also tried to call the Win32 API 
accept(NULL,NULL,NULL) from within OnAccept() and the client still gets a 
connection made.

Thanks for any help and best regards,
Danny

0
8/30/2006 5:34:02 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
823 Views

Similar Articles

[PageSpeed] 21

If you don't call Accept then the connecting socket will timeout.
Or you can simply shotdown the listening socket.

I would personally Accept the connection but then turn around and send a
message that the connection limit has been reached and then disconnect it.

AliR.

"Danny Pressley" <DannyPressley@newsgroup.nospam> wrote in message
news:DD2D3DCA-F863-412C-A7BC-4D0F2C3D2A3A@microsoft.com...
> Hello,
>
> I am using CAsyncSocket for my client/server application, everything works
> fine and I can open as many socket connections as I want, but I would like
to
> limit the number of connections (say 10 sockets at any one time). During
the
> OnAccept() call of my listen socket, is there something I can do to refuse
> the connection, or maybe some other way outside of OnAccept(). Once my
open
> socket count goes back below my set limit, I would like to start accepting
> connections again until the limit is maxed out again.
>
> FYI: I've tried to not call Accept() from within OnAccept(), but the
client
> side still gets a connection made. I've also tried to call the Win32 API
> accept(NULL,NULL,NULL) from within OnAccept() and the client still gets a
> connection made.
>
> Thanks for any help and best regards,
> Danny
>


0
AliR3470 (3236)
8/30/2006 6:27:32 PM
For MFC's CAsyncSocket, it is not possible to accept connections
conditionally.  As Ali indicated, the best approach is to accept the
connection and then turna around and send a "connection limit exceeded"
message followed by a disconnect.

An advanced winsock2 function, WSAAccept, will allow you to define a
callback function that makes accept/reject decisions.  See the lpfnCondition
parameter at
http://msdn.microsoft.com/library/en-us/winsock/winsock/wsaaccept_2.asp .
However, this function probably cannot be used with MFC's socket classes.

Mike

"AliR" <AliR@online.nospam> wrote in message
news:44f5d8f4$0$15209$a8266bb1@reader.corenews.com...
> If you don't call Accept then the connecting socket will timeout.
> Or you can simply shotdown the listening socket.
>
> I would personally Accept the connection but then turn around and send a
> message that the connection limit has been reached and then disconnect it.
>
> AliR.
>
> "Danny Pressley" <DannyPressley@newsgroup.nospam> wrote in message
> news:DD2D3DCA-F863-412C-A7BC-4D0F2C3D2A3A@microsoft.com...
> > Hello,
> >
> > I am using CAsyncSocket for my client/server application, everything
works
> > fine and I can open as many socket connections as I want, but I would
like
> to
> > limit the number of connections (say 10 sockets at any one time). During
> the
> > OnAccept() call of my listen socket, is there something I can do to
refuse
> > the connection, or maybe some other way outside of OnAccept(). Once my
> open
> > socket count goes back below my set limit, I would like to start
accepting
> > connections again until the limit is maxed out again.
> >
> > FYI: I've tried to not call Accept() from within OnAccept(), but the
> client
> > side still gets a connection made. I've also tried to call the Win32 API
> > accept(NULL,NULL,NULL) from within OnAccept() and the client still gets
a
> > connection made.
> >
> > Thanks for any help and best regards,
> > Danny
> >
>
>


0
8/30/2006 6:57:52 PM
Reply:

Similar Artilces:

How do I select duplex printing using my new Dell 968w in Outlook
How do I use my new Dell 968w (wireless) inkject printer with duplexing option to print in Outlook on both sides of page "automatically?" Thank you. "math horizons" wrote in message news:0298E5DB-6BBC-42F0-9BF9-2790A1EB1145@microsoft.com... > How do I use my new Dell 968w (wireless) inkject printer with > duplexing > option to print in Outlook on both sides of page "automatically?" > Thank you. Not an Outlook issue. This is a printer issue in what configuration options are available when you choose to print to that printer. http://accessories....

Fresh Win7, IE8 no connect with firewall enabled ...
Installed a fresh install of Windows7 (no upgrade), enabled windows firewall and allowed program through firewall and I am unable to connect. When firewall is disabled, IE connects. Something in windows firewall blocking but I cannot find it. What am I missing? Robin Did you format the HDD prior to installing Win7? What anti-virus application or security suite is installed and is your subscription current? Do other applications connect? Are you connecting via dial-up, cable, ADSL, satellite, or wireless internet USB modem? Is a router involved? Why can’t I connect t...

I download, accept, and the it downloads again
When I download from Capital One, I am notified that I have statements to read. I go into the account, and accept them (there are two). The next time I open Money, it automatically downloads the same two items. So, the last time I used Money, I decided to just keep them as new, and not Accept them. Sure enough, today when I connected, it downloaded them again, so now I have 2 of each new item. Does anyone know of a fix for this? Thanks... jbryant789 I have this exact same problem with all of my accounts. I have had a support case opened since 09/21... no fix yet. They keep getti...

How to turn off maximizing other documents when opening a new word
When you have a few word documents minimizes and you open a new word document, one of the minimized documents maximizes too. Is there a way to get rid of that annoyance? ...

2003 office EULA Dialog box after accepting agreement contiues to.
2003 office EULA Dialog box after accepting agreement continues to appear after I start word, outlook,excel etc.. The product has been activated. Is this caused by windows 7? See the following http://support.microsoft.com/kb/884202 -- Peter Please Reply to Newsgroup for the benefit of others Requests for assistance by email can not and will not be acknowledged. "PRICJAMP" <PRICJAMP@discussions.microsoft.com> wrote in message news:DF70CB7A-357D-42B0-B6C4-06BD68C1235E@microsoft.com... > 2003 office EULA Dialog box after accepting agreement continues to ...

How create & use list of date-based tasks to use on each new case?
I have a list of, say, 50 date based tasks that need to be done on each new client. E.g. when a new client is obtained, five tasks might run from the CLIENT OBTAINED date. Ten more tasks might be based on the TREATMENT ENDED date. Another fifteen various tasks might be based on the LAST DATE AUTHORIZED date. It's the same routine for each new client. Once a particular 'anchor' date is known, I know the dependant task is due, say, 5 days after the CLIENT OBTAINED date, or another task is due 30 days before the LAST DATE AUTHORIZED date, and another task is due the day of the...

Outlook Is Not Connecting To Hotmail Server
My Outlook is not connecting to the Hotmail server. What could be causing this issue? Here is the detailed report: Outlook Hotmail Connector Version 14.0.4760.1000 Session timed out. Automatically re-signed in at 6/3/2010 7:33:15 PM Mail: Error at 7:33 PM. Calendar: Contacts: Last successfully refreshed at 7:33 PM. ...

Add Template directory to the New Publication
How do I add "Template" to the list in the New Publication list under Backgrounds. I have a lot of templates and don't want to have to view them one at a time. The instructions I have to load them to publisher is to copy them into the "Applicatio Data" folder, listed as "documents and Settings/username/application data/microsoft/templates" however I don't have that one on my computer. Is there another way to access them than from this folder - listing them the same way you can for other "Pre-designed" projects? Thank you anyone who can ...

how do i get publisher 2003 to print in pantone on my new zerox 6.
i have a new 6250dp Zerox Phaser Tectronix printer. I cannot get the colors in Publisher to print correctly. Can someone tell me what to do? A small child turns to Ed, and exclaims: "Look! Look! A post from lori <lori@discussions.microsoft.com>!"... > i have a new 6250dp Zerox Phaser Tectronix printer. I cannot get the > colors in Publisher to print correctly. In what way are your your colours not what you want? Is it, say, that colours are generally a little too light or too dark, or that green is printing as blue, or pink as green? -- Ed Bennett - MVP Microsoft...

connect to shared printers
I have two shared printers on an XP PC - i can install one of the drivers locally but when I try to connect to (install as) remote printer 7 says it cannot find the install files and looks for inf files. The other, an Epson Stylus 600 - it appears there's no drivers for 7 - is this correct? Thanks, J. Is your Windows 7 machine 64 bit? (Assume yes since you are posting in a 64 bit specific newsgroup). There are supposed to be drivers for both 32/64 supplied with Windows/WU. http://www.microsoft.com/windows/compatibility/Windows-7/en-us/Details.aspx?type=Hardware&p=Eps...

Connect to Exchange using http keeps checking itself
Running Exchange 2007, I have one user in our office who occasionally will have their Outlook 2007 check the connect to Microsoft Exchange using HTTP box and then the Only Connect to proxy servers that have this principal name in their certificate. We use a certificate just one you can create yourself, we don't have issues with other people who use the certificate to connect with outlook from their homes but when in the office this user occasionally will have outlook check this for him. He unchecks the area and it works for awhile but eventually it returns. Any help wou...

How to create new lead for existing customer?
We are tracking all new leads, whether it is a new prospect or new lead within an existing customer. But when you enter a new lead, it will not allow you to pull an existing account. You have to rekey all company data. Any thoughts? Seems kind of like a backwards approach (which is why there's no option to do this). I would think you would just create a new contact inside an existing account. -- Brandon IT Director Presentations Direct - Office Equipment & Supplies http://www.presentationsdirect.com "Jan Kratochvil" <Jan Kratochvil@discussions.microsoft.com>...

Wanted: skilled programmer for new NZ startup company
A unique opportunity. A new New Zealand based e-commerce startup is looking for an enthusastic and skilled programmer to develop innovate e-commerce solutions and help to set the direction of the company. A generous payment package (including company shares & revenue shares) will be provided for the selected candidate. Required skills: - C++, C#, XML, MS .Net, Web Services; software archirecture design - positive, 'can do' attitude - fluent English A valid NZ work visa is also required! When you think this description fits your profile, submit your CV+application letter to etr...

Help please
OK - I took the plunge and "upgraded" to Money 2005 D. I'm now at an impass - I'm update two of my credit card accounts to sync up with their on-line service providers. When I do that, Money '05 telle me that I need to disable MSN bill pay to add the accounts. When I disable MSN billpay, I AM able to add the accounts and sync them up, BUT: My balances (primary checking) go crazy and I'm unable to get BillPay working again. BillPay now refers to a checking account that doesn't exist and won't allow me to point it back to my primary account. So, 1) Can ...

Exchange 2003 GAL address list new user not showing up
I have somewhat of a difficult problem to troubleshoot here... Heres the scenario: 1) I have a existing user that I've tried to setup with an email account. The email account was created no problem and the user has a proper SMTP address. (This indicates that the recipient update service is working) 2) I can send the user email using his full email address, however the user is not in the GAL. Once I sent him an email, his mailbox populated into the private information store. 3) This is *not* an cached exchange mode issue where I need to download the latest gal. I have done this seve...

Clients loosing connection to server
I have an Exchange 2003 server running in a Windows 2003 AD domain. Starting a week ago, all of my clients will periodically loose the connection to the server. In some cases, the connection will be lost and then it will reconnect, then several minutes later, the connection is lost again. When this is happening, if you close Outlook, you can not get back in because it can't find the Exchange server. I work for a school district and the Exchange server is at one location, but we have eight other sites connecting to the Exchange server and the problem seems to be happening at all ...

Moving mailboxes to a new exchange server; size limit.
We currently have one exchange server in our company. We saw the need for another one so we created a new exchange server and added it to our current forest. <h3>We are trying to move mailboxes from the old exchange server to the new one. Some of the mailboxes we are moving are over 2GB's, the question will there be any problems doing this?</h3> it will take some time, but if there are no limits on either server, prohibiting send or send/receive, you should be able to move the mailboxes... -- Susan Conkey [MVP] "Heber" <Heber@discussions.microsoft.com&g...

AD connection
How do I configure Outlook 2000 to see the Active Directory user info - I would like to use AD as my global email address book for the company. ...

Inbox doesn't show new emails in Outlook 2007
When I am looking in the Inbox and new emails arrive they don't appear although the number of unread emails in the Inbox increases. I have to select another folder and then return to the Inbox to see the new emails. -- Peter Saxton from London peter@petersaxton.co.uk What kind of email account? Do you have any anti-virus Outlook plugin disabled, especially AVG's? Patrick Schmid -------------- http://pschmid.net "peter@petersaxton.co.uk" <peter@petersaxton.co.uk> wrote in message news:f9vb82hg7m14to2ep3pr3qkh761bbo0k3d@4ax.com: > When I am looking in the Inbo...

How to disable and enable the internet connection
Hi All, i am a new guy to network programming. any one can tell me how to disable or slow the internet connection. REGARDS ranjith Lots of ways, pick one: 1. Pull network cable. 2. Uninstall network card driver. 3. Uninstall tcp/ip. 4. Misconfigure your IP address and/or network mask and/or gateway and/or DNS. 5. Turn the DSL/Router power off. 6. Cancel your account with the ISP. Some of those you can do programmatically too... "mappla" <ranjithsubra@gmail.com> wrote in message news:1181168054.223682.131480@i38g2000prf.googlegroups.com... &...

dialog for each new document
Hello, I want that my application shows a dialog each time a new document is created. What I've done is to create the dialog in the OnFileNew() of the application class. An example: void CMyApp::OnFileNew() { CWinApp::OnFileNew(); AfxMessageBox("Initial message"); } My problem is that when I open the application only the message is shown, but the application is not shown in the background. �What I do wrong? Thanks in advance. This sounds like your project is for an MDI application. The MDI application won't display it's window until the OnFileNew returns to the...

Accepting macros
Hello, I have been reading posts in the newsgroups about forcing (well no actually possible, I know) the user to accept macros - suggestion offered included making the worksheet less useable when macros wer disabled. One popular suggestion was to have a warning sheet asking the user t enable macros if the user hadn't enabled macros. This would requir that such a sheet be created and made 'very hidden' in th workbook_open event and finally made visible in workbook_beforeclos event and SAVE the workbook. The problem with this method is that th workbook is saved everytime it is cl...

how do i set up a new user in an old one in outlook?
i'm trying to set up my account where i work, but the one old who belonged to an old employee still show up and when i send emails, are on his name. i already set up my account when it asked me but still on the old employee's name. what could i do? carlodc22 <carlodc22@discussions.microsoft.com> wrote: > i'm trying to set up my account where i work, but the one old who > belonged to an old employee still show up and when i send emails, are > on his name. i already set up my account when it asked me but still > on the old employee's name. what could i do? ...

Outlook cannot connect to Exchange Server
I'm having an issue with two PCs (both with Outlook 2003 and with both Windows XP SP2 RC1). This issue has been going on before XP SP2 RC1 and Outlook 2003 but I hoped by upgrading to newer versions it would resolve my issue but obviously no luck. The issue I am having is that I cannot access my Exchange server from the local intranet through Outlook. I can ping the server, I can get on via OWA but I cannot get on through Outlook itself. When I set up the profile and go to validate / "CHECK NAME" I see no activity lights over the LAN and it comes back 45 seconds lat...

New Webcam and VB6 source code
Hello, I wrote some months ago a source used to visualize video from multiple webcams and to save image files from each ones. This was made with with either WIA or avicap in VB6.0. I just try to make it run with the Microsoft Lifecam Cinema that seems to allow an image size of 1280*720. Everything good except the selection of this size of the capture on this device. It doesn't give me a choice heigher than 640*320. Could someone give me an idea of what the problem could be? I have tried to find the good graph to implement with graphedit (with which it runs) but I am no...