Ive created one socket in the app and then made a variable array and set the type to the Socket.
I understand how to increase , decrease , connect ,etc the Variable array, But what i can not figure out is:
when a i add a connected , error , data avaliable event handler to the socket. Is there any way of finding out which index of the array is connecting or had a error???
No, i did not. Im having a hard time understanding the subclass and how it works.
At this point. I have physically dropped a tcpSocket on the window and called it MYSocket then i added a property to the window, called it Sockets and made it a array and set the type to MYSocket.
Does that makes sense?
Thank you for your Response, I dont normally post i just struggle for days until i figure something out, But this is confusing me.
I’m going to answer this in a different order than you wrote it
[quote=57237:@adam sion]At this point. I have physically dropped a tcpSocket on the window and called it MYSocket then i added a property to the window, called it Sockets and made it a array and set the type to MYSocket.
Does that makes sense?
Thank you for your Response, I dont normally post i just struggle for days until i figure something out, But this is confusing me.[/quote]
Ah yeah that’s not doing what you think it is
If you have instances you dropped on the window you can add the code to each instance in its event handlers.
And you can set it up so you can add new instances dynamically (see Control Sets) in the documentation.
Then each instance knows which one it is and you don’t need to worry about it as far as the array is concerned (in fact you do not need the array at all)
A subclass is a specialized version of whatever the super class is.
So say you created a new class and set it’s super to be “TCPSocket”
Then you can, in your subclass, add the various event handlers for error etc and write the code in the subclass to handle those events.
And each instance that you create will also “know” which events it gets (they are not shared)
Its probably worth your time to go through several bits of documentation rather than just start writing code since the documentation will help explain this (especially about classes & subclasses)
If you go to http://documentation.xojo.com
The Introduction to Programming with Xojo book is a great place to start
And there are 4 User Guides
The User Guide consists of 4 books that cover what you need to know to start creating apps using Xojo.
Book 1: Fundamentals (176 pages) PDF (6MB), iBooks (14MB)
Book 2: User Interface (167 pages) PDF (6MB), iBooks (11MB)
Book 3: Framework (219 pages) PDF (4MB), iBooks (11MB)
Book 4: Development (95 pages) PDF (6MB), iBooks (9MB)
Just to Confirm when you created your “class” and set the type you set it to TCPSocket right? Above you just typed TCP which isn’t wont work for you. Yes after you set this you will see your Class icon change in the IDE to a globe network thing
I am rather new to Xojo, but I use TCPSockets all the time. That isn’t correct as I have been using it.
The Sockets.append isn’t correct unless again there is another way I don’t know of
Here is a snippet when I instantiate my TELNET(TCPSocket) class
My Custom TCPSockets Class is Named: CMD_COLLECTION_TELNET
////////////////////////////////////////////
// Use TELNET Collection //
//////////////////////////////////////////
TELNET = New CMD_COLLECTION_TELNET
TELNET.Address = IpAddress
TELNET.Port = val(ConnectingPort)
////////////////////////////////////////////////////////////////////////
// Connect to Remote Device and Begin Connect Routines //
//////////////////////////////////////////////////////////////////////
Dim TimeOut as Double = 5000000
StartSessionTimer = Microseconds
TELNET.Connect
Do
TELNET.Poll
Loop until TELNET.IsConnected or (Microseconds - StartSessionTimer > TimeOut)
Also under my “CMD_COLLECTION_TELNET” Subclass I use it’s Connected Event to issue commands for example and then I use it’s DataAvailable event to receive the results.
I never have created the socket array, however that part looks easy after you implement your subclass’s events correctly as Norman suggested above.
HTH.
Its all Working. Im just looking for confirmation that I am doing it Correctly.
Seems like I am.
The part that is throwing me for a loop. Is when I create 3 Instances of my Socket Array and Pause my app. It shows 3 Sockets. If i then Delete 1 of my Socket arrays and pause my app. The Array is Correct, But the app still shows 3 Sockets??
Usually if I have more than one socket open they show up in the IDE while debugging (paused) no matter if that Socket IsConnected = True or False. Until you Close the socket you will see it in the debugger when paused.