Madz Posted May 4, 2003 Posted May 4, 2003 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 ? Quote The one and only Dr. Madz eee-m@il
*Gurus* Derek Stone Posted May 5, 2003 *Gurus* Posted May 5, 2003 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. Quote Posting Guidelines
Madz Posted May 6, 2003 Author Posted May 6, 2003 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. Quote The one and only Dr. Madz eee-m@il
*Gurus* Derek Stone Posted May 6, 2003 *Gurus* Posted May 6, 2003 You shouldn't be concerned with the Active property once you've inherited from TcpClient. Use the Poll method instead. Quote Posting Guidelines
Madz Posted May 7, 2003 Author Posted May 7, 2003 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 Quote The one and only Dr. Madz eee-m@il
*Gurus* Derek Stone Posted May 7, 2003 *Gurus* Posted May 7, 2003 Originally posted by Derek Stone You shouldn't be concerned with the Active property once you've inherited from TcpClient. Use the Poll method instead. Quote Posting Guidelines
Madz Posted May 10, 2003 Author Posted May 10, 2003 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. Quote The one and only Dr. Madz eee-m@il
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.