Solved

Getting Address in Use while connectihg thru Sockets

Posted on 1998-12-14
4
253 Views
Last Modified: 2013-12-26
I am trying to connect using sockets. However I get EADDRINUS error.
Any idea why ???
0
Comment
Question by:sjohn
4 Comments
 

Expert Comment

by:Gunnar
ID: 1294829
This message generally occurs when you create a server socket and the specified port is occupied by a different socket. However, as I understand your question you are trying to create a client socket (in which case you do not specify a port number anyway), is this correct?
0
 
LVL 2

Accepted Solution

by:
rdelfino earned 100 total points
ID: 1294830
I suppose you're trying to create a client application  that uses stream sockets (TCP) and I think you tryed to bind (calling bind()) the socket before trying to connect. You do not have to bind the
socket before connecting. The OS do it automatically to you
when you call connect() - except when  an error occurs.

Try this:

/* includes . . . */
int main(void)
{

int s;
int port;
struct sockaddr_in sockAddr;

/* initializing . . .*/

s = socket(AF_INET, SOCKSTREAM, 0);
if (s <0)
{
 printf("Error %d . . .\n", errno);
 exit(0);
}

memset(&sockAdd, 0, sizeof(sockAddr);
port = 2000; /* use the port you want */

sockAddr.sin_family = AF_INET;
sockAddr.sinport = port;

sockAddr.sin_addr.s_addr = inet_addr("143.107.45.230");
/* use the IP addres you want */

if (connect(s, &sockAddr, sizeof(sockAddr))<0)
{
 printf("Connect error %d . . .\n", errno);
 exit(0);
}

/* the rest of your program . . .*/

}

I hope it helps

Reginaldo

0
 

Author Comment

by:sjohn
ID: 1294831
I believe I had not been specific in defining my scenerio under which I am getting this error

I have a client using TCP based SOCK_STREAM communication. I am not calling bind and just creating the socket and calling connect(). The server is not under my control and is written by some one else.

The problem occures when I close the socket and try to connect to the same server IP address. This is when I get Address in Use, Connect failed
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6823641
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.

This is the Community Support link, if help is needed, along with the link to All Topics since many new ones were recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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