in reply to connect() & close()

You have autoflush enabled right? Sounds like a buffer that needs to be sent before closing the socket. (Im no socket expert)