You can make use of WMI; look at the Win32_NetworkAd apter class for this.
Use the classes under System.Manageme nt 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.Sele ctQuery("Win32_ NetworkAdapter" )
Dim oObjSearcher As New Management.Mana gementObjectSea rcher(oQuery)
Dim oBaseMgmtObj As Management.Mana gementBaseObjec t
For Each oBaseMgmtObj In oObjSearcher.Ge t()
For Each oProperty as Management.Prop ertyData in
oBaseMgmtObj.Pr operties()
Debug.WriteLine ("Name: " & oProperty.Name & vbTab & "Value: " &
oProperty.Value )
Next
Next oBaseMgmtObj
the properties applicable to the Win32_NetworkAd apter object are listed
here:
http://msdn.microsoft.com/library/de...orkadapter.asp
one of the properties is the 'NetConnectionS tatus' 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" <sz**********@M poczta.onet.pl> wrote in message
news:cf******** **@news.onet.pl ...
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.Conn ected
Try
Thread.Sleep(10 0)
If Me.mSocket.Avai lable > 0 Then
Dim lBuffer(Me.mSoc ket.Available) As Byte
Me.mSocket.Rece ive(lBuffer)
If lBuffer.Length > 0 Then
mstrDataIn =
System.Text.ASC IIEncoding.ASCI I.GetString(lBu ffer)
RaiseEvent DataReceived(ms trDataIn)
mstrDataIn = ""
End If
End If
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
End While
all the time mSocket(TcpList ener) has Connected = True even when I
disconect
How I can detect this situation?
Regards
Szafranr