Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 15, 2017 2:33 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: EasyTCPsocket console application
PostPosted: Mon Dec 24, 2012 7:24 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
I have a client/server desktop application using EasyTCPsocket client side.

I need to code a console version of the client but cannot find any examples. My desktop client currently has an super EasyTCPsocket class named mysocket and button on the main form.

My button connect code is:

mysocket.Address = "server.mydomain"
mysocket.Port = 22
mysocket.Connect


Mysockets connected event is

Connector.SendMessage( Val( "51" ), data )



My question is how would this be done as a console application the client also needs to handle receivedMessage events etc....

Any help is gratefully appreciated

Oh and Image everyone.....

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPsocket console application
PostPosted: Mon Dec 24, 2012 1:01 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
In a ConsoleApplication, you have to provide your own event loop. This is the intended use of app.DoEvents. In the Run event of the ConsoleApplication, connect your socket and then loop:
mysocket.Address = "server.mydomain"
mysocket.Port = 22
mysocket.Connect

while True
app.DoEvents(50)
wend


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPsocket console application
PostPosted: Wed Dec 26, 2012 10:19 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:)

Tim thanks for you advice...

I still think I am doing something incorrect

What I have done is created a new console app project. In the project tab of the IDE I have added a class (type EasyTCPsocket) and named it mysocket.

Then in my APP run event I have added the code:

mysocket.Address = "server.mydomain"
mysocket.Port = 22
mysocket.Connect

while True
app.DoEvents(50)
wend


When I compile and run the project I get the error "This item does not exist mysocket.Address="server.mydomain"

I can only presume that i need to do things at runtime like maybe

dim mysocket as new EasyTCPSocket


:?:

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPsocket console application
PostPosted: Wed Dec 26, 2012 1:53 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Adding a class creates an object definition. Adding a property creates an object reference. You must create an object reference and instantiate the object before you can use it.

Add a class if you want to put code in its events, which you probably do.

Add a property of your class type to create a globally available reference. (Since this is a console app, DIM'ing a variable in the Run event is almost the same thing. So, your choice which way you go.)

Create a new object in the Run event before you try to use it.


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPsocket console application
PostPosted: Sat Dec 29, 2012 4:56 am 
Offline
User avatar

Joined: Fri Oct 28, 2005 7:05 am
Posts: 565
Location: Emsworth, UK
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

_________________
Yes it's me in the avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: EasyTCPsocket console application
PostPosted: Mon Dec 31, 2012 10:44 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:) All working now thanks to you msssltd

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group