For localhost use address = “localhost” otherwise your firewall may require you to open the port. Are you communicating with another Xojo Application? How are you “listening” in that?
The socket works async so it can’t be connected immediately after you want to connect.
Either you have to add your TCPSocket to a window and the implement the events Connected and Error. Or you have to do an AddHandler for the events and create methods for the events.