Set State of TCPSocket?

Good Day Everyone,
Have a very newbie Question :3
I want to create 2 apps one on a remote server and another on my computer, and by using the TCPSocket to send packets now the thing I can’t figure out is if I have a console app with a TCPSocket … where do I tell the socket to enter a Listening state? … A run event? If so then will it be fine Under App and not under the socket itself?

P.S Not asking for code just a nudge in the right direction.

THanks

Do it right after creating the instance of your socket. Have a look at ServerSocket though, that will create a pool of sockets which will allow re-connection after the socket is closed. Alternatively set the tcpsocket back to a listening state in the error event handler if the lasterrorcode is 102.