object instances in Custom Objects

E

Eric Cathell

I am creating a custom TCPDatagram object. I am using :

mTcp() as tcpClient
mNetstream() as NetworkStream

below is the actual code with my questions at the end.

Public Class TCPDatagram

Private mTcp() As TcpClient

Private mNetStream() As NetworkStream

Public Property TcpData(ByVal i As Integer) As TcpClient

Get

Return mTcp(i)

End Get

Set(ByVal Value As TcpClient)

mTcp(i) = Value

End Set

End Property

Public Property NetStream(ByVal i As Integer) As NetworkStream

Get

Return mNetStream(i)

End Get

Set(ByVal Value As NetworkStream)

mNetStream(i) = Value

End Set

End Property

Public Sub OpenDatagram(ByVal ip As String, ByVal index As Integer)

Try

'============================

ip = "192.168.155.99"

'============================

TcpData(index).Connect(ip, 4000)

NetStream(index) = TcpData(index).GetStream

Catch ex As Exception

Debug.WriteLine(ex.Message)

End Try

End Sub

Public Sub CloseDatagram(ByVal index As Integer)

Try

NetStream(index).Close()

TcpData(index).Close()

Catch ex As Exception

Debug.WriteLine(ex.Message & "," & "CloseDatagram")

End Try

End Sub

Public Sub New(ByVal index As Integer)

ReDim mTcp(index)

ReDim mNetStream(index)

End Sub

End Class 'TCPDatagram



my quetion is when i go to open the datagram through OpenDatagram, and i
pass it all the right information I am getting an instance object exception
in that procedure...but i dont know why...



my calling code instanciates the class using new, I am not inheriting from
TcpClient because I am not extending it, i am just trying to make a
connection object that uses it...any help here?



Thanks

Eric
 
A

_Andy_

Public Sub New(ByVal index As Integer)

ReDim mTcp(index)

ReDim mNetStream(index)
' (Add these lines in place)
Dim counter As Integer
For counter = 0 To index
mTcp(counter) = New TcpClient()
Next
End Sub

End Class 'TCPDatagram



my quetion is when i go to open the datagram through OpenDatagram, and i
pass it all the right information I am getting an instance object exception
in that procedure...but i dont know why...

You had allocated an array to _hold_ TcpClient objects. You had NOT
created any TcpClient objects. i.e. mTcp() was an array containing a
load of Nothings.
my calling code instanciates the class using new, I am not inheriting from
TcpClient because I am not extending it, i am just trying to make a
connection object that uses it...any help here?

You class doesn't look like a TCPDatagram - it looks more like a
connection pool. Or are you intending to implement some kind of
server?

Rgds,
 
E

Eric Cathell

You class doesn't look like a TCPDatagram - it looks more like a
connection pool. Or are you intending to implement some kind of
server?

I didnt really know what to call it...hehe...It probably could be considered
a connection pool. I have several printers that are connected to my network
via client bridges...they are used to print palletmarkers. I have a thread
setup for each printer, this part of the code is where I am opening up the
connection...checking the printer status then printing the label...I am
refining my code to hopefully make the process as fast as possible...before
i was doing several connections and it was being handled inside the monitor
instead of as a seperate entity....

thanks for the info...I would not have caught that...i figured i needed to
use the New tcpClient somewhere...just didnt know where...

Thanks again...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top