What is the difference between tcpsocket.close and .disconnect methods?

When using TCPSockets, can anyone tell me the difference between the .Close and .Disconnect methods? Should they both be used or just one?


Close automatically calls Disconnect. Also, the socket will be disconnected and closed when it goes out of scope. So the following all get the job done.

sock = Nil
sock =  New TCPSocket

Hi Tim,

Thanks four your response!
I do not want to destroy the socket, I have like 25 pre-created, so i just want to disconnect and close them, then reuse. With that, not necessary to set it to Nil correct?

Thanks Tim,

A connected TCPSocket holds a reference to itself, thereby keeping itself in scope, until the other side disconnects. The TCPSocket documentation calls this “orphaning” the socket.


Good to know.

1 Like

Be aware that double closing sockets can lead to a crash: Big Sur ServerSocket Trouble - #7 by Mike_D

If after closing a socket, does it need to be re-instantiated? Or is it just closed and can be used again?

It can be reused without being re-instantiated.