TCPSocket array

Hi,

Im struggling with a TCPSocket array.

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???

Thanks in advance

Adam

Did you create a subclass & implement those events in the subclass ?
And then you add instances of your subclass to the array ?

Some code of how you set up you classes & the array would help me give you better advice.

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 :stuck_out_tongue:
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)

And there are a pile of webinars etc available as well http://documentation.xojo.com/index.php/Videos

Thanks will do

So I have read the documentation and would like to confirm That I am setting up my TCPSocket array correctly.

I have Created a class and set the type to TCP.(My class now becomes a subclass by default?)

I then create a Property array that is set to the type of my Created Class(Subclass).

Dim S As new MyTCPSocket///Class
S.address = “192.168.0.50”
S.port = 23
S.Connect
Sockets.Append(s)///Property Array

This Code adds a new instance of my class to the project?

Thanks

Adam

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 :slight_smile:

That is correct.

So am I understand and setting up the Class Correctly?

Also, If I understood the Documentation correctly.
If I Add 3 sockets to the app thru the process above and then decide to (Sockets.Remove(Integer).

By Removing a instance of the Socket Array. Xojo will deal with making that Particulay Socket no longer valid beacuse I am no longer refering to it??

I ask that because when I pause the app and look at the Socket array it shows what I am expecting to see, But the app itself still show # Sockets??

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 :slight_smile:

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)

Then to close the Socket I just issue the TELNET.Close or TELNET.Disconnect.

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. :slight_smile:
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??

Does that make sense??

Whats the code you are using to disconnect your 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.

Sockets.Remove(1)

//Sockets=Property Array

Where are you Closing your socket? That is probably why it is still showing up in the IDE even though your Array is correct.

  1. TCPSOCKET_SUBCLASS.CLOSE
  2. Remote from Array.

So I should write

Close the socket then append my array?

That makes Sense!!! Dont know why i was not doing that.

Ill give it a shot now.

Thank you for taking the time!!!