Solved

Getting Address in Use while connectihg thru Sockets

Posted on 1998-12-14
4
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 132
unix example issues 18 112
Bartender label printing - switch on and off graphics 3 92
Adjust the codes 3 60
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

734 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