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.
For example...
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
MyEasyTCPSocket.Connected
Print "Socket connected to " + me.Address
me.SendMessage( Val( "51" ), data )
End sub
MyEasyTCPSocket.Error
if me.LastErrorCode = 102 then
Print "Socket lost connection"
else
Print "Socket error " + cstr(me.LastErrorCode)
end if
end sub
MyEasyTCPSocket.DataAvailable
Print "Socket has " + cstr(me.BytesAvailable) + " bytes waiting"
end sub
Application.Run
Dim MySocket1 as new MyEasyTCPSocket
MySocket1.Address = "host.domain"
MySocket1.Port = 22
MySocket1.Connect
Do
MySocket1.Poll
Loop until MySocket1.IsConnected
While MySocket1.IsConnected
App.DoEvents
Wend
End sub
When writing console applications you need to think carefully about object persistence and scope.
For example...
MyEasyTCPSocket.Connected
//Scope error!
// Connector is not a part of the MyEasyTCPSocket subclass
Connector.SendMessage( Val( "51" ), data )
End sub