CyberPsychotic wrote:

>  here I was writing some code to initiate connection in endless loop, and
> got stuck abit.. I would be greateful, if you could clarify some things. 
> so I had in my code:
> 
> sockfd=socket(..);
> while(1)
> {
> connect();
> write();
> read() with select() till remote closes connection(read returns eof);
> }
> 
> but I feel like I will have to disconnect socket first, b/c I get "socket
> is already connected otherwise".
> I wonder how should this be done?

With close().

> all what comes in mind is:
> 
> 
> while(1)
> {
> sockfd=socket(..);
> connect();
> write();
> read() with select() till remote closes connection(got eof);
> close(sockfd);
> }
> 
> but isn't it an overkill?

No. Unless you don't actually need to keep connecting and
disconnecting that is.

> also, does connect modify sockaddr_in structure (so I would have to renew
> it every time) or it's save enough to do it once. (so far I haven't noted
> connect does any mess with it, but... )

connect() shouldn't modify the `struct sockaddr'.

The prototype should have used `const struct sockaddr *', except that
the `const' keyword didn't exist when the sockets API was developed.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to