473,748 Members | 4,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);
//Set the reuse address flag.
ws_socket.SetSo cketOption(Sock etOptionLevel.S ocket,SocketOpt ionName.ReuseAd dress,(int)1);

//Call connect which works.
ws_socket.Conne ct(...)
//Here i perform my socket work.
....
//Get the local endpoint & close the socket.
EndPoint endpoint = ws_socket.Local EndPoint;
ws_socket.ShutD own(...)
ws_socket.Close ();

//Now create a new socket and try to reuse the address.
ws_socket = new
Socket(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);
ws_socket.Bind( endpoint );
//Here is where it throws the exception.
// System.SystemEx ception {"Only one usage of each socket address
(protocol/network address/port) is normally permitted"}
System.SystemEx ception
ws_socket.Conne ct(...)


Dec 5 '05 #1
1 9438
It is necessary to call
ws_socket.SetSo cketOption(Sock etOptionLevel.S ocket,SocketOpt ionName.ReuseAd dress,(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******** *******@TK2MSFT NGP12.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(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);
//Set the reuse address flag.
ws_socket.SetSo cketOption(Sock etOptionLevel.S ocket,SocketOpt ionName.ReuseAd dress,(int)1);

//Call connect which works.
ws_socket.Conne ct(...)
//Here i perform my socket work.
...
//Get the local endpoint & close the socket.
EndPoint endpoint = ws_socket.Local EndPoint;
ws_socket.ShutD own(...)
ws_socket.Close ();

//Now create a new socket and try to reuse the address.
ws_socket = new
Socket(AddressF amily.InterNetw ork,SocketType. Stream,Protocol Type.Tcp);
ws_socket.Bind( endpoint );
//Here is where it throws the exception.
// System.SystemEx ception {"Only one usage of each socket address
(protocol/network address/port) is normally permitted"}
System.SystemEx ception
ws_socket.Conne ct(...)

Dec 5 '05 #2

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

Similar topics

2
7121
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 this. The part I'm concerned with is the cell FFFFF which contains a multiple <SELECT> list of <OPTION>s. As you can see the first two rows span more than one column (if this has any importance). What I want is to constrain FFFFF not to exceed a...
0
2016
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 option in there to optimize the code, has anyone had any expeiance / problems with this option and were there any significant gains in performance by turning on this setting?
1
6133
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 server (who knows it first) closes the socket and than wants to establish the SAME connection again ( due to firewall reasons it has to be the SAME IP AND PORT).
6
4125
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: Connect Receive response Send Connect ACK
1
2715
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 sends something to server, everything works fine (i.e. server received what client sent). But if I try to make server send anything, client receive 0 byte although server send a correct bytes size. Any idea ?
1
372
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() { CONNECTION = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
1
2675
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 certificates are installed and running (postmaster starts fine). When I try to connect I get the following Error Message PostGreSQL Error Code(1): invalid connection option "requiresll"
4
1921
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 there is a TIME_WAIT value, but I thought I could get around it by using the ResuseAddress option. Here is what the code looks like (C#): Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
4
4315
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 the crash each time. We finally think we have narrowed down the cause of this to a user (located semi-remotely) who would connect into our system and disconnect "ungracefully" (literally, by pulling his network cable). Connections here are all...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.