On Mon, 30 Jul 2001, Kai Mueller wrote:

> On Mon, Jul 30, 2001 at 07:51:43AM -0700, Estabridis, Janet P wrote:
> [...]
> > Unable to establish a port Connection:  Address already in use. 
> 
> I received this message many times. I didn't understand it
> completely but it seems to be a timer in the tcp stack code
> which allocates a released port a certain amount of time
> (perhaps to allow a reconnection of a broken connection).
> 
> No need to reboot. Just wait a few seconds.
> 

Hi,

I remember having an error like this in my network programming class (in
unix), and this is what one of my classmates had put up for us to use.  (I
might be totally off on the correct solution, but we were doing socket
programming as well).


  int sockfd, i = 1;
  if ((sockfd = socket(AF_INET,SOCK_STREAM,0))==-1)
    {
      perror("socket");
    }
  setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,(void*)&i,sizeof(i));
  ^^^^^^^^^^^^^^^^^^^
*** 
That line seemed to do the trick.  I don't really know what the i
variable is for (I was just happy that my problem was solved).  I had been
getting the port still in use error, and that line fixed it up for me. 
***

  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(atoi (argv[1]));
  server_addr.sin_addr = *((struct in_addr *) he->h_addr);
  if (connect (sockfd, (struct sockaddr *) &server_addr, sizeof (struct
sockaddr)) == -1)
    {
      perror ("connect");
      exit (-1);
    }

  close (sockfd)




Hope that helps!

George Sun

----- End of forwarded message from [EMAIL PROTECTED] -----
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/

Reply via email to