Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Aug 16, 2017 6:28 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: TCPSocket array
PostPosted: Fri Feb 22, 2013 6:52 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hello,

I made app for monitoring PC apps via TCP.
Recently I add "Multi Monitor" mode which allows checking all defined apps.
I created for it multi page window with infobars, which are created via NEW command as arrays.
So in real if I have defined 18 PCs, there are e.g 18 labels, 18 icons, 18 rectangles etc.. and 18 TCPSockets . All as arrays.

Problem is if "DataAvailable" fires, CPU usage raises to 99% for a couple of seconds and app is unresponsive.
Between events app shows 1-3 % of CPU.

Maybe workflow with TCPSocket as array is not good, but what other way is acceptable ?

Thanks

Martin

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Fri Feb 22, 2013 11:22 am 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
mapmusic wrote:
Hello,

I made app for monitoring PC apps via TCP.
Recently I add "Multi Monitor" mode which allows checking all defined apps.
I created for it multi page window with infobars, which are created via NEW command as arrays.
So in real if I have defined 18 PCs, there are e.g 18 labels, 18 icons, 18 rectangles etc.. and 18 TCPSockets . All as arrays.

Problem is if "DataAvailable" fires, CPU usage raises to 99% for a couple of seconds and app is unresponsive.
Between events app shows 1-3 % of CPU.

Maybe workflow with TCPSocket as array is not good, but what other way is acceptable ?

Thanks

Martin


Show us how you use your array.

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Fri Feb 22, 2013 4:51 pm 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hello,

Simple sample for my workflow :
In Design stage I have created TCPSocket, Label, Canvas.
All objecs has Index=0.


On Open event of window I have code like:

Dim TCP as TCPSocket, Lab as Label, Can as Canvas

For i=1 to AppsCount
TCP = new TCPSocket
Lab= new Label
Can= new Canvas
TCP.Address=IP(i)
TCP.Port=Prt(i)
TCP.Connect
Lab.text=str(IP(i))
Next

Where IP() and Prt() are global variables predefined by user.
This is way how I create arrays.

Then on DataAvailable event of TCPSocket I have code like:

Sub DataAvailable(index as Integer)
Dim LSData as string
LSData=me.ReadAll

dim plm as string=MG_ParseListener(LSData,"PLAYMODE")
select case plm
case "play"
Canvas(index).Backdrop=play
case "stop"
Canvas(index).Backdrop=stop
case "cue"
Canvas(index).Backdrop=cue
case "pause"
Canvas(index).Backdrop=pause
end select

End Sub


Where MG_ParseListener function returns one of status used in select case .

Code is more complicated, but this is way how I used TCPSocket array.

On each DataAvailable I got unresponsive app.

Martin

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Fri Feb 22, 2013 8:21 pm 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
I see now you are using it as a control-array.

You can better just handle the TCPSocket array yourself.
Create a Property Sockets() As myTCPSocket on your window, app or a module.
Create a Subclass from the project tab, then set it's super to TCPSocket.

Now everytime you need a new Socket you create it as:
Dim Socket As new myTCPSocket
Socket.address = "somedomainORipaddressHere"
Socket.port = 1024

MyWindow.Sockets.Append( Socket ) 'Add the new client Socket to the array.


Replace myWindow with your Sockets() array parent (window, app or module name).

You can use Sockets( INDEX ).[method,property] to access the socket on that index.
Use Ubound(Sockets) to get the number of sockets.

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Mon Feb 25, 2013 4:12 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Hi swort,

I do not understand exactly...

myTCPSocket in your example is class defined in project level with TCPSocket Superclass ?
Or it is physical object added in design time ?
How to access Sockets(x).DataAvailable event ? ... Where can I add code for this event ?

Thanks

M.

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Mon Feb 25, 2013 9:14 am 
Offline

Joined: Tue Oct 30, 2012 4:23 am
Posts: 22
Uff,

I just found bug with my code, so lags was caused by my mistake.
SO I have no freezes also with control-array based sockets.

Anyway...Can you tell me advantage of your way compare to control array ?

Thanks

Best Regards

M.

_________________
---

@MacOS 10.7.5/MBPro


Top
 Profile  
Reply with quote  
 Post subject: Re: TCPSocket array
PostPosted: Mon Feb 25, 2013 9:31 am 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
mapmusic wrote:
Uff,

I just found bug with my code, so lags was caused by my mistake.
SO I have no freezes also with control-array based sockets.

Anyway...Can you tell me advantage of your way compare to control array ?

Thanks

Best Regards

M.


Well, if you keep your "own" array (as a property) you have better control over it.
A control array works best with UI controls.

If you create a subclass with super of TCPSocket then you can handle all your code in that subclass.
The property can be on any global class (window, app, module) if you need it on the window, when ever the window is closed then your array will also be closed.

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group