Timeout

Myst

New member
Joined
Jan 19, 2004
Messages
2
Location
Germany
Using VB.Net to establish a network connection Im having a slight problem!

All I want to do is catch a timeout error. As soon as my server notices that the connection cannot be established for a certain amout of time I want to put out a MsgBox. Ive already tried to solve it with a Timer, but it wont work out.
Maybe someone has an Idea:

Public Function Verbindung()
Const portNumber As Integer = 8000
Dim tcpListener As New TcpListener(portNumber)
tcpListener.Start()
Try
** Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim clientdata As String = Encoding.ASCII.GetString(bytes)

**Thats where I get the Problem. TcpClient doesnt answer and the whole thing gets stuck!

HELP!!!!
(I need the darn thing for work!)
 
Put the init code into a thread then have a status boolean value to tell you if you have connected.

So, you can startup the thread and loop for a certain amount of time waiting for the boolean to turn true.
 
Back
Top