You are pretty close to the solution.
Dim MySocket as new EasyTCPSocket
Creates an instance of an EasyTCPSocket class.
You can not populate the event handlers of a built in object in a console application, so it's pretty useless.
What you want to do is subclass the EasyTCPSocket Class, populate the events and then create an instance of this new class.
Add a new Class to the project in the project explorer.
Set the Class name to MyEasyTCPSocket
Set the super to EasyTCPSocket
Double click MyEasyTCPSocket
Populate the event handlers as follows
Print "Socket connected to " + me.Address
me.SendMessage( Val( "51" ), data )
if me.LastErrorCode = 102 then
Print "Socket lost connection"
Print "Socket error " + cstr(me.LastErrorCode)
Print "Socket has " + cstr(me.BytesAvailable) + " bytes waiting"
Dim MySocket1 as new MyEasyTCPSocket
MySocket1.Address = "host.domain"
MySocket1.Port = 22
Loop until MySocket1.IsConnected
When writing console applications you need to think carefully about object persistence and scope.
// Connector is not a part of the MyEasyTCPSocket subclass
Connector.SendMessage( Val( "51" ), data )