Sockets and Collections

  • Thread starter Thread starter Shawn D Shelton
  • Start date Start date
S

Shawn D Shelton

Hi,

I have a collection containing about 300 items. Each item is a custom
class containing some user information collected by my program. Is there
any way to send the entire collection over a socket connection or would
I have to enumerate through the collection and send each item on it's own?

thanks
Shawn
 
Is there any one who could at least take the time for a yes or no answer
or at least confirm my suspicions?

thanks
Shawn
 
I think this is possible. If the collection object is serialized, all of
it's items are serialized too. On the other end, the complete collection
will be rebuilt.
 
Hi,

I have a collection containing about 300 items. Each item is a custom
class containing some user information collected by my program. Is there
any way to send the entire collection over a socket connection or would
I have to enumerate through the collection and send each item on it's own?

thanks
Shawn

There is a million ways to do this. The normal method (no matter what
the language) is to implement serialise methods that accept a stream
as an argument in any object that requires serialisation. ie. The
class, and the collection class. This is an example of a model:

' Person [class]
'
'

Imports System.IO

Public Class Person
...
Public Sub Write(outputStream As Stream)
Dim oWriter As New BinaryWriter( outputStream )
oWriter.Write( Me.Surname )
oWriter.Write( Me.Forenames )
oWriter.Write( Me.Age )
End Sub
...
End Class


' PersonCollection [class]
'
'

Imports System.IO

Public Class PersonCollection
...
Public Sub Write(outputStream As Stream)
Dim oWriter As New BinaryWriter( outputStream )
oWriter.Write( Me.Count )
Dim oPerson As Person
For Each oPerson In Me.Items
oPerson.Write( outputStream )
Next
End Sub
...
End Class



So, you can now write these objects to any Stream (file, network
etc..) You should implement the deserialise methods ("Read") to
populate the object with the data in the stream.
 
Back
Top