Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am developing a Network Application i am facing problem , in VB6 Winsock control we have 6 states of Winsock control so we can determinte at which state now socket it. in .net i have implemented a TCPLISTNER server which listnes and connects client , now the problem is that when server is closed, the tcp client still assumes it is connected, how can i check wether this connection is active or not ?

When i write netstat -a it shows me that connection is on Close_Wait , but the TCP Client has only 2 states true or false ,

 

Please tell me how can i check wether at this time my connection is active or not ?

The one and only

Dr. Madz

eee-m@il

  • *Gurus*
Posted
You can retrieve the state from the TcpClient's underlying socket through TcpClient.Client. You'll need to inherit from TcpClient to access this property, since it is protected. The Active property, to which you're referring to, is not updated when the connection is closed by the remote host.
Posted

Inherited Property

 

it was exectly the same, coz the active state is also inherited from base class. otherwise it is not accessable through normal code.

Thanks for your help.

The one and only

Dr. Madz

eee-m@il

Posted

Still i am unable to get what i want to do , here i develop a class with this code

Imports System.Net.Sockets

Public Class MyClient
   Inherits System.Net.Sockets.TcpClient

   Public Property MyState() As String
       Get
           Dim s As Socket = Me.Client

           If s.Connected = True Then
               Return "I am Connected"
           Else
               Return "I am not Connected"
           End If
       End Get
       Set(ByVal Value As String)

       End Set
   End Property

End Class

 

if a from my client i am doing this

 

   Dim X As MyClient = New MyClient()

   Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
       X.Connect("localhost", 4896)


   End Sub

   Private Sub cmdStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStatus.Click
       MsgBox(X.MyState)
   End Sub

 

If i connect to some Server it connects , in case connection is dropped from server then it always shows that this is connected.

 

I want to be notified when a connection is closed.

 

can any please provide me some code

The one and only

Dr. Madz

eee-m@il

Posted

Problem Solved

 

Thanks Dear

 

My Problem has been solved, i used this

 

Public Property MyState() As String
       Get

           Dim sck As Socket = Me.Client
           If sck.Poll(1, SelectMode.SelectRead) = False Then
               Return "Still Connected"
           ElseIf sck.Poll(1, SelectMode.SelectRead) Then
               Return ("Lost Connection")
           End If

       End Get
       Set(ByVal Value As String)

       End Set
   End Property

 

 

and in application i did this

 

console.writeline(Client.myState)

 

and it returns exect the same what i wanted.

The one and only

Dr. Madz

eee-m@il

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...