LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-04-2010, 05:01 AM   #1
hboosh
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Rep: Reputation: 0
how to close a socket and refuse waiting connections?


hi,

i've written a socket server. when i launch a client, it connects to servers running on various machines on my local network, which then reply to the client with some string messages, and the client exits.

however, when i launch the client repeatedly (say 5 or 6 times in quick succession) the client is unable to bind to its local port. this appears to be because servers are still trying to connect to the client machine's port, even though the client exited and shut the socket down. the actual error i receive is "Error binding socket to 192.168.1.6:44561: Address already in use".

so, is it enough just to shutdown and close a socket? is there some way that in doing so the client machine can send a CONNECTION_REFUSED message to any machine trying to connect to it? i am using PHP, not that that should make much of a difference i hope.

the problem resolves itself after around 20 seconds as the machines trying to connect to the client timeout. i still need to fix this issue though.

thanks,
haz

Last edited by hboosh; 01-04-2010 at 05:29 AM.
 
Old 01-04-2010, 02:34 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
After you close a server socket, you should wait a while (that's TCP feature). You can also set socket option to SO_REUSEADDR. Example usage and code here:
http://php.net/manual/en/function.socket-set-option.php
 
Old 01-05-2010, 02:59 AM   #3
hboosh
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
ok thanks. it's not going to be used in a super high availability environment, so it shouldn't cause a problem. i'm already using SO_REUSEADDR.
 
  


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
Python: work while waiting for socket connection? hbar Programming 4 10-27-2010 04:57 AM
ubuntu 7.10 aft upgrade f/7.04 , rdesktop, ssh, refuse connections rocket777 Ubuntu 1 10-21-2007 06:46 PM
msec configuration causes libwrap to refuse connections MJatIFAD Linux - Security 7 09-13-2003 04:40 PM
Programs refuse to close sometime... TippyToes Linux - General 3 08-13-2003 05:45 PM
waiting for X server to begin accepting connections . redhat_zephyr Linux - Newbie 10 07-07-2003 11:27 PM

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

All times are GMT -5. The time now is 07:17 AM.

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