Archived Forum Post

Index of archived forum posts

Question:

Socket Server Connection Test

Mar 13 '14 at 05:21

Hello All,

I Am trying to write my first app in VB.NET 2012 using the Chilkat software. I am attempting to create a GUI-based socket server using the async methods in the "Socket" module. However, I am struggling to find a way to periodically test the "connected" status of the socket and update a label on my form. The "IsConnected" property always returns false whether my client app is connected or not.

Here is my code (timer driven):

Private Sub tmrSockCheck_Tick(sender As Object, e As EventArgs) Handles tmrSockCheck.Tick
    Select Case lblAWOSSocket.Tag
        Case "0"
            Success = Socket.BindAndListen("20003", "1")
            If Success = True Then
                lblAWOSSocket.Tag = "1"
            Else
                lblAWOSSocket.Tag = "-1"
                MessageBox.Show(Socket.LastErrorText, "Error Binding Socket", MessageBoxButtons.OK)
            End If
        Case "1"
            lblAWOSSocket.BackColor = Color.Orange
            Success = Socket.AsyncAcceptStart("0")
            If Success = True Then
                lblAWOSSocket.Tag = "2"
            Else
                lblAWOSSocket.Tag = "-1"
                MessageBox.Show(Socket.LastErrorText, "Error Initializing Socket", MessageBoxButtons.OK)
            End If
        Case "2"
            lblAWOSSocket.BackColor = Color.Yellow
            Success = Socket.AsyncAcceptSuccess And Socket.AsyncAcceptFinished
            If Success = True Then
                lblAWOSSocket.Tag = "3"
            End If
        Case "3"
            lblAWOSSocket.BackColor = Color.Green
            If Socket.IsConnected <> True Then
                lblAWOSSocket.Tag = "1"
            End If
        Case "-1"
            lblAWOSSocket.BackColor = Color.Red
    End Select

What basically happens is that the code waits for a connection and then when my client makes the connection, the connection is closed by my application and then moves through the "AsyncAcceptStart", "AsyncAcceptSuccess" / "AsyncAcceptFinished" phase of my program before it is dropped again.

Am I right in assuming that the "IsConnected" property is for a "Client" application?

Thanks, Greg