[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Binding error when trying to reconnect to the same port after closing a socket.

Posted on 2004-10-19
3
Medium Priority
?
313 Views
Last Modified: 2010-04-22
Here it goes.  I have two processes running: the client and the server.

The server opens up a control port and starts accepting connections (it only handles one connection at a time).

The client then opens up and connects to the server.  When it does, it opens a data port (the client is the server of the data port) and starts to accept connections on that data port.

Then the client sends one of 4 commands to the server: get, put, list, or quit.  Get gets a file, put puts a file, list lists all the files, and quit quits.

When the client sends the quit, the server closes that particular socket and the data socket, and goes back to accepting the next connection.

Now, my problem is that, if I quit (close the client), then reopen the client right away and try to connect to the server, I can't bind to the same port.

I realize there is some kind of UNIX time_out thing that protects the port for a while if the socket doesn't terminate right, but mine does (as far as I know - I close the socket and everything)

And even more strange, I only get binding errors if before I disconnect I do a "put" command... nothing happens if all I do is a "get" or "list"... does sending data in the client->server direction have anything to do with it?

I'd apreciate if someone could clear up my mind on this one.

Gustavo.
0
Comment
Question by:gugario
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
NVRAM earned 200 total points
ID: 12349912
0
 
LVL 4

Expert Comment

by:NVRAM
ID: 12350193
Your use model sounds very similar to part of the FTP protocol (which I presume you realize).  

It sounds like you have a persistent and transient process; and they are using the non-passive mode that FTP uses (client connects to server on command port, then will bind & send a port to server for data).


> The client then opens up and connects to the server.  When it does, it opens a data port
> (the client is the server of the data port) and starts to accept connections on that data port.
>
> Now, my problem is that, if I quit (close the client), then reopen the client right away and try to connect to the server, I can't bind to the same port.

Typically with TCP/IP the term "server" implies the process that does the bind/accept and "client" implies the process that does "connect".

When you say "the client is the server" do you mean that it does a bind/accept or simply that it is the one writing to the socket?  

Presuming the former (bind/accept in transient "client") then the SO_REUSEADDR is probably your fix.

But, if you simply mean it serves the data, then your persistent process ("server") has already bound on the data port and shouldn't need to again, so move the bind/accept outside the command-port accept loop.

Hope that helps.




0
 
LVL 1

Author Comment

by:gugario
ID: 12352672
Thanks a lot for the clarifications!  I used the SO_REUSEADDR option and it worked. I was under the false impression that if I closed the socket the right way I could avoid the TIME_WAIT problem, but apparently not.  Since I know I'm closing it right, SO_REUSEADDR is perfect.

Thanks again!

Gustavo
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question