473,387 Members | 1,573 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,387 software developers and data experts.

SO_REUSEADD successful but bind fails for release version - debug version no problem

I have been facing a problem with UDP socket programming. I have to reuse port number for two different IP address. I am actually using SO_REUSEADD. I have no problem with debug version but with release version the bind is failing for 2nd IP address with the error code 10048. It's the error code for WSAEADDRINUSE. I am trying to with WinXP machine using Visual C++ 6.0.

The application which we are using needs to connect to Primary and Backup server. The UDP connection should be established with both Primary and Backup server so that if the Primary server goes down, the client can still communicate with backup server and retrieves all information.

I can’t use different port for both Primary and Backup serer as we are allowing multiple clients on a PC. Also we are not handling this on the server side since it’s a redundant system.

Primary Server (Listening Port : 6000)
Backup Server (Listen on 6000)

Client1 (Listening Port 6003: Local Port: 6002 so that the server knows it should send it to 6003, just add one and send the response back)
Client2 (Listening Port 6005: Local Port: 6002 so that the server knows it should send it to 6003, just add one and send the response back)

I have a mechanism to select both listening and local port on the client. I bind with the specific portnumber and close the socket after identifying the port numbers.

The setsockopt is successful for SO_REUSEADDR but bind fails for backup server. It’s strange that this issue never happens in debug version but release version fails to bind for the backup server.

Here is the code to handle this scenario.

WSADATA WsaData;
int err = WSAStartup(MAKEWORD(1,1), &WsaData);
if ( err != 0 )
{
return (kOpenInvalidDev);
}
if ((mSocket = socket(PF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
{
return (kOpenDevError);
}
int optval;
if(!mIsServer)
{
if (setsockopt(mSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &optval,
sizeof (optval)) == SOCKET_ERROR)
{
close(); // close.
return (kOpenDevError);
}
}
if (setsockopt(mSocket, SOL_SOCKET, SO_BROADCAST, (char *) &optval,
sizeof (optval)) == SOCKET_ERROR)
{
close(); // close.
return (kOpenDevError);
}
else if (mLocalAddr.sin_port != 0)
{
if (bind(mSocket, (struct sockaddr*)&mLocalAddr, sizeof(mLocalAddr)) ==
SOCKET_ERROR)
{
return (kOpenDevBusy);
}
}
}
Jun 25 '08 #1
1 2466
This issue has been resolved. The issue was with the project settings. The customization was set up Maximum Speed. I have changed it to default and solved the problem. Thanks for the support.
Jun 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: KeithO | last post by:
Problem: App works OK in debug both in VS.Net and build version. Also OK as release version in VS.net Not working as release version build. Gets to this line of code: (private func called...
2
by: John Beschler | last post by:
I have a c# function that runs fine in VS.Net when in debug mode; however, when I switch to Relase mode or compile the app, the function fails with "object refernce not set". Here is the whole...
5
by: David++ | last post by:
Hi there, I have built a DLL in Visual C++ 6. When I build the DLL it builds fine for the debug version of the DLL (and this DLL works fine), however, I seem unable to build a Release version of...
10
by: babak | last post by:
Hi everybody I'm working with a project in embedded Visual Studio 4 and I have a general problem which I hope that somebody can help me with. My problem is the following: My project works fine in...
5
by: Joachim | last post by:
I needed to change the name of the project folders, e g. |-MyProject | |-MyProject to something else. Now it doesn't matter what I do - even if I rename the folders to the original name the...
2
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The...
4
by: nmrcarl | last post by:
I'm trying to upgrade a large project from VS 6.0 to VS 2005. After fixing a lot of things that changed (mostly sloppy coding in the original project that VS2005 didn't allow), I got the release...
0
by: Russ | last post by:
I have a Web Service that was originally created with .NET VC 2003, and subsequently converted to the 2005 version. It works fine when built as a debug version, and run on the workstation it was...
3
by: Russ | last post by:
I have a Web Service that was originally created with .NET VC 2003, and subsequently converted to the 2005 version. It works fine when built as a debug version, and run on the workstation it was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
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...
0
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,...

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.