VBE 2005 NetworkStream Question

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

Dim clt as TcpClient
Dim stm as NetworkStream

clt = New TcpClient()
clt.Connect("192.168.0.200", 9999)
Do Until clt.Connected
Loop
stm = clt.GetStream
' --The following line throws "Object reference not set to an instance of an
object."
stm.BeginRead(buf, 0, 4096, AddressOf ReadEvent, Nothing
' --This also throws the same exception
stm.Close

I can find nothing in the documentation that says this is wrong.

Help? Thanks.
 
What version of framework are you using? I don't see a "connected"
property for the tcpclient object in 1.1.

Regardless, I see that you have a Do..Loop there to make sure that the
client obejct can connect, but put a breakpoint on the
stm=clt.getstream line and then check the state of clt.connected again.
If it is closed, the GetStream method returns a ObjectDisposed
Exception, and so it is unable to "stm" to referense anything.
 
apologies, as soon as I clicked on the submit button, I noticed you had
VBE 2005 in your subject (VBSEG), so that answers which framework you
used. :)
 
I found the problem.

This...
stm.BeginRead(buf, 0, 4096, AddressOf ReadEvent, Nothing)
Should be...
stm.BeginRead(buf, 0, 4096, AddressOf ReadEvent, buf)
 
Back
Top