You can make use of WMI; look at the Win32_NetworkAdapter class for this.
Use the classes under System.Management namespace to retrieve the network
adapter information.
for instance, the following code will loop through all network adapters
listing their properties:
Dim oQuery As New Management.SelectQuery("Win32_NetworkAdapter")
Dim oObjSearcher As New Management.ManagementObjectSearcher(oQuery)
Dim oBaseMgmtObj As Management.ManagementBaseObject
For Each oBaseMgmtObj In oObjSearcher.Get()
For Each oProperty as Management.PropertyData in
oBaseMgmtObj.Properties()
Debug.WriteLine("Name: " & oProperty.Name & vbTab & "Value: " &
oProperty.Value)
Next
Next oBaseMgmtObj
the properties applicable to the Win32_NetworkAdapter object are listed
here:
http://msdn.microsoft.com/library/de...orkadapter.asp
one of the properties is the 'NetConnectionStatus' which you can look at to
determine whether the adapter
is disconnected or connected or something else. You can look up these values
from the link above.
hope this helps..
Imran.
"Szafranr" <(E-Mail Removed)> wrote in message
news:cf5uji$l9q$(E-Mail Removed)...
> Hi
>
> I have application where I used tcpListener to connect with another
system.
> Every thing is ok that it's time to error handling
> and I have problem
> when the TCP client is disconect I don't know how detect this situation
> the same situation is when I plug out patch-cord
>
> For waiting for a data I use this loop
> While Me.mSocket.Connected
> Try
> Thread.Sleep(100)
> If Me.mSocket.Available > 0 Then
> Dim lBuffer(Me.mSocket.Available) As Byte
> Me.mSocket.Receive(lBuffer)
> If lBuffer.Length > 0 Then
> mstrDataIn =
> System.Text.ASCIIEncoding.ASCII.GetString(lBuffer)
> RaiseEvent DataReceived(mstrDataIn)
> mstrDataIn = ""
> End If
> End If
> Catch ex As Exception
> MsgBox(ex.ToString)
> End Try
> End While
>
> all the time mSocket(TcpListener) has Connected = True even when I
disconect
>
> How I can detect this situation?
>
> Regards
> Szafranr
>
>