Socket problem

P

piotrek

Hello all.

I have a problem and my solution but i have to make sure that it want cause
memory problems.
i have a class FTP and 'private Socket CONNECTION = null;'

Then i have a method PASV()
{
CONNECTION = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
......
IPEndPoint ep = new IPEndPoint(IPHost.AddressList[0] , port);
CONNECTION.Bind(ep); CONNECTION.Listen(1);

....
}

1. Object of FTP is created.
2. PASV is called once.
3. CONNECTION is closed.
4. PASV is called twice.
5. Cannot bind - only one usage of socket address is normally permited -
exeption.

i dont exactly understand why i cant bind when i closed socket before i bind
again.
Also thought that i can make Collection of Private sockets, but iam not sure
if it want cause that closed and unused sockets will occupy the memory.
If there is better solution - wothout making Collection, please let me know.
Thanks for your time.

PK
 
V

Vadym Stetsyak

it seems to me that the connection is not completely closed when your socket
is closed. ( CLOSE_WAIT state ). To fix the problem you have to enable the
address reuse socket option.

you can do that utilizing SetSocketOption(...) method of the Socket class.
Option name is SocketOptionName.ReuseAddress.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top