Real Software Forums
http://forums.realsoftware.com/

TCPSocket array
http://forums.realsoftware.com/viewtopic.php?f=2&t=47033
Page 1 of 1

Author:  mapmusic [ Fri Feb 22, 2013 6:52 am ]
Post subject:  TCPSocket array

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

Author:  swort [ Fri Feb 22, 2013 11:22 am ]
Post subject:  Re: TCPSocket array

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.

Author:  mapmusic [ Fri Feb 22, 2013 4:51 pm ]
Post subject:  Re: TCPSocket array

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

Author:  swort [ Fri Feb 22, 2013 8:21 pm ]
Post subject:  Re: TCPSocket array

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.

Author:  mapmusic [ Mon Feb 25, 2013 4:12 am ]
Post subject:  Re: TCPSocket array

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.

Author:  mapmusic [ Mon Feb 25, 2013 9:14 am ]
Post subject:  Re: TCPSocket array

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.

Author:  swort [ Mon Feb 25, 2013 9:31 am ]
Post subject:  Re: TCPSocket array

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/