0
votes

this maybe a topic for years but I could not really figure out how to make this right.

So I started a project in vb6 using winsock control to send and receive messages from computers connected on LAN.

In my project I include two winsock controls, namely con and conn. con will listen to connection request and let conn accept the request, so conn is in an array to accept multiple request from clients

Private Sub con_ConnectionRequest(ByVal requestID As Long)
    If conn(0).State = sckClosed Then
        conn(0).Accept requestID
    Else
        Load conn(socknum)
        conn(socknum).Accept requestID
    End If
    socknum = socknum + 1
End Sub

Now that there are multiple clients connected, clients can send message to the host but the host could only send text messages to the last index of conn or that the client who connected last will be the only one that could receive the messages from the host.

Private Sub txtSend_KeyPress(KeyAscii As Integer)
    Dim n As Integer
        If KeyAscii = 13 Then
            If ishost = True Then
                For n = 0 To conn.UBound
                   If conn(n).State = sckConnected Then
                       conn(n).SendData txtSend
                   End If
                Next n
            Else
                con.SendData txtSend
            End If
            txtMessages.Text = txtMessages.Text & vbCrLf & txtSend.Text
        End If
End Sub

I could not figure out whats wrong with my code so please a little help or hint is very well appreciated.

1

1 Answers

0
votes

Where is the variable ishost defined? Could you please post that code?

Also please post the pieces of code that assigns a value to ishost.

Where is the variable socknum defined? Could you please post that code? Is socknum used anywhere else?

To debug: place a breakpoint on the line For n = 0 To conn.UBound and step through the execution with F8. Does the execution reach this line? What is the value of conn.UBound?