Solved

Getting Address in Use while connectihg thru Sockets

Posted on 1998-12-14
4
250 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now