hello,
write a signal handler to close the socket, and you'll be fine.
otherwise, the system closes it for you, but it takes a bit.


Thanks,
_|_|_|_|_|  _|        _|_|_|_|            
    _|      _|_|_|    _|          _|_|_|  
    _|      _|    _|  _|_|_|    _|        
    _|      _|    _|  _|        _|        
    _|      _|    _|  _|_|_|_|    _|_|_|  
Visit TDS for quality software and website production
http://tysdomain.com
msn: [EMAIL PROTECTED]
aim: st8amnd2005
skype: st8amnd127
  ----- Original Message ----- 
  From: John Matthews 
  To: [email protected] 
  Sent: Tuesday, August 26, 2008 10:00 AM
  Subject: [c-prog] sockets - bind() error, address already in use


  I've got a client and server program communicating over a stream
  socket. They are C programs compiled using gcc running under Linux.

  The server calls socket(), bind(), listen(), then loops round calling
  accept() and creating a thread to read() messages on the connection.
  The thread exits when the read() returns 0 (indicating EOF on the socket).

  The client calls socket() and connect() to connect to the server, then
  write() to send messages to it.

  This all works fine, until I stop the programs using CTRL-C. Then when
  I re-run the server I sometimes get a 'address already in use'
  returned by bind(). However, if I wait a minute or 2, it's ok again.

  I guess it's because I'm not closing down the socket properly or
  something. I'm no socket expert - what am I missing out?

  Cheers
  John



   

  __________ NOD32 3387 (20080826) Information __________

  This message was checked by NOD32 antivirus system.
  http://www.eset.com


[Non-text portions of this message have been removed]

Reply via email to