LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2004, 01:05 AM   #1
SoulSkorpion
LQ Newbie
 
Registered: Oct 2004
Distribution: Knoppix
Posts: 6

Rep: Reputation: 0
Question restricting incoming connections, using sockets


Hi.

I'm doing some sockets-based programming for a uni assignment. The code that handles the connecting, sending and receiving is working fine, since it's based on code from a previous assignment.

The problem is that this time my server program must use threads, each connecting client being handled by a seperate thread. Also, the number of threads is fixed at startup, and the threads must all be created at the beginning (rather than creating them as clients connect).

Anyway. I've got most of this working ok. The problem is that there is a very definite limit on the number of simultaneous connections, but I can't work out how to get the server to stop accepting connections once the limit's been reached, then resume accepting them once space becomes available.

The closest I've come is shutting down\closing the listen socket when the server's at max, but I can't seem to reopen the listen socket. Closing the listen socket seems to work, as far as blocking incoming connections goes, but nothing I can think of to resume listening is working. Mostly, the problem seems to be "address already in use". It's not working to simply try to listen on the same file desc again, nor to create and bind a new socket.

So... am I going about this completely the wrong way?
 
Old 10-19-2004, 06:43 AM   #2
anoop_cv
LQ Newbie
 
Registered: Oct 2004
Location: Kerala, India
Distribution: Debian
Posts: 3

Rep: Reputation: 0
I think what u are trying to do is the way to do it. The problem of "address already in use" can be solved by the use of "setsockopt" call, with an option to resuse the address.

sample usage is given below
int yes = 1;
setsockopt(sockfd, SOL_SOCKET,SO_REUSEADDR, &yes, sizeof(int));

dont forget to do the error checking ;-)
 
Old 10-20-2004, 03:15 AM   #3
SoulSkorpion
LQ Newbie
 
Registered: Oct 2004
Distribution: Knoppix
Posts: 6

Original Poster
Rep: Reputation: 0
That seems to be working! Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Listening for incoming connections vital_101 Mandriva 9 09-20-2005 08:26 PM
Restricting the # of SMTP Connections per IP kemplej Linux - Security 1 05-10-2005 01:35 PM
restricting remote connections dominant Linux - General 0 03-03-2004 11:56 AM
Restricting XWindows remote connections (iptables) Harpune Linux - Networking 4 02-17-2004 06:03 AM
Sendmail and incoming connections mike_smith Linux - Networking 3 01-19-2004 06:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration