473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problems with socket ReuseAddress option

Bob
I am trying to reuse a socket address but I am having problems. What I am
doing is creating a socket, connecting, then getting the LocalEnd point. I
then Disconnect and try to connect again using the same address but I get an
error 10048 [WSAEADDRINUSE]. Can someone tell me what I am doing wrong.
Here is the code...

ws_socket = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
//Set the reuse address flag.
ws_socket.SetSocketOption(SocketOptionLevel.Socket ,SocketOptionName.ReuseAddress,(int)1);

//Call connect which works.
ws_socket.Connect(...)
//Here i perform my socket work.
....
//Get the local endpoint & close the socket.
EndPoint endpoint = ws_socket.LocalEndPoint;
ws_socket.ShutDown(...)
ws_socket.Close();

//Now create a new socket and try to reuse the address.
ws_socket = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
ws_socket.Bind(endpoint );
//Here is where it throws the exception.
// System.SystemException {"Only one usage of each socket address
(protocol/network address/port) is normally permitted"}
System.SystemException
ws_socket.Connect(...)


Dec 5 '05 #1
1 9397
It is necessary to call
ws_socket.SetSocketOption(SocketOptionLevel.Socket ,SocketOptionName.ReuseAddress,(int)1);
for the second instance of Socket class.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Bob" <ms****@hotmail.com> wrote in message
news:uH***************@TK2MSFTNGP12.phx.gbl...
I am trying to reuse a socket address but I am having problems. What I am
doing is creating a socket, connecting, then getting the LocalEnd point. I
then Disconnect and try to connect again using the same address but I get
an error 10048 [WSAEADDRINUSE]. Can someone tell me what I am doing wrong.
Here is the code...

ws_socket = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
//Set the reuse address flag.
ws_socket.SetSocketOption(SocketOptionLevel.Socket ,SocketOptionName.ReuseAddress,(int)1);

//Call connect which works.
ws_socket.Connect(...)
//Here i perform my socket work.
...
//Get the local endpoint & close the socket.
EndPoint endpoint = ws_socket.LocalEndPoint;
ws_socket.ShutDown(...)
ws_socket.Close();

//Now create a new socket and try to reuse the address.
ws_socket = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
ws_socket.Bind(endpoint );
//Here is where it throws the exception.
// System.SystemException {"Only one usage of each socket address
(protocol/network address/port) is normally permitted"}
System.SystemException
ws_socket.Connect(...)

Dec 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: LC's No-Spam Newsreading account | last post by:
I have a form arranged in a table (you can see an example in the page http://cosmos.mi.iasf.cnr.it/~lssadmin/Website/LSS/Help/query.html) The table is on three columns but has a structure like...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
1
by: Joe | last post by:
Hi, I browsed the news and a few seem to have this problem too, but no solution ! I have a client server application where in case the connection gets bad (crashes or whatever) client or...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
1
by: EppO | last post by:
I wrote a small server/client app. I created a class for my customized socket object using (synchronous) Sockets functions for both server and client use. When client connects to server, if It...
1
by: piotrek | last post by:
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()...
1
by: Otto Blomqvist | last post by:
Hello ! I'm writing a DB app using Delphi 7. The PostGres Delphi components we are using are PostGreDAC from MicroOLAP, the latest ODBC drivers (from postgre.org)and PostGres 7.2.2. The...
4
by: carl_bevil | last post by:
I would like to use a single port to connect to a server. I would like to be able to disconnect a socket using this port and then be able to connect again (on the same port) immediately. I know...
4
by: Adam Clauss | last post by:
A while back I posted regarding a problem we were having with one of our applications which was randomly crashing. Monitoring memory usage revealed a spike in nonpaged pool memory just prior to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.