Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting Address in Use while connectihg thru Sockets

Posted on 1998-12-14
4
Medium Priority
?
258 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 400 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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