URGENT!! NetworkStream "null reference" problem.

I

Inspired

Hi, im writing an application that uses tcpclient to connect.

I have a class which makes the whole network stuff.. As below:

Public Class Connections
Private Client as tcpclient
Private Stream as network stream

Public Sub Connect()
Client.Connect(..)
Stream = Client.GetStream()
End Sub
Public Function Send( str as string ) someStr as string
.... Some encoding then ..
Stream.Write(...)
..
..
End Function
End Class

I uses this class from another class called "ClientClass", in this
class I have functions each one should send data using the previous
class's functions.

Public Class ClientClass
Private ConnecObj as new Connections

Private Function Login()
ConnecObj.Connect()
ConnecObj.Send(...)
..
..
End Function

Private Function GetUsers()
ConnecObj.Send(...)
End Function
End Class

In each of these functions i uses the "ConnecObj.Send(..)" directly
,except the first function "Login" i call the "ConnecObj.Connect()"
first to let the Stream has a reference.

THE PROBLEM is:
Every function except the login raises an exception telling that the
stream has a null reference.
I can fix it by calling ConnecObj.Connect() before each
ConnecObj.Send() but im opening a thread for client ( request ) , by
this way I hv to open a thread for send of each client.
Any idea is appreciated
Thanx in advance.
 
G

Guest

hi, im by no means an expert on this but from when ive used network streams,
it looks like ur declaration might b wrong? but thats just a thought,
whenever ive used them, i always do this:

''Global Var Socket and stream
Private ClientSocket As Socket
Private ClientStream As NetworkStream

''Code to connect socket...however u chose to do it, then once socket is
connnected do this

ClientStream = new NetworkStream(ClientSocket)

thats walways worked for me without fail...so i hope that helps
 

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