borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2016 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Networking Router)Next Topic (Introduction to Networking Free Download) New Topic New Poll Post Reply
AndreaVB Forum : Network : Need help connecting multiple clients in chat program
Poster Message
Sacom
Level: Trainee

Registered: 01-10-2006
Posts: 1

icon Need help connecting multiple clients in chat program

I'm rather new to net coding in VB6 and I have a problem. I read the tutorial on the now-dead winsockvb.com awhile ago, and I have just made a few changes to it myself. I was trying to make it so that multiple clients could connect to one server, and it would act sort of like IRC. But, I'm having an odd problem. I made it so that whenever a client sends some text, instead of sending it out and assuming it got to the server and adding it to the "sent text" box itself, it would just send it to the server, and then the server would send it back to ALL clients, including the one that sent it. This solved two problems, 1) making the sender sure that his message hit the server and 2) removing the specific client from the loop to send his message to other clients. My problem then is, that for some reason the server only communicates with the most recent client connected unless forced otherwise. An example of this can be seen here:

Private Sub Winsock_DataArrival(Index As Integer, ByVal bytesTotal As Long)

Dim strData As String
Dim i As Integer
    
    Winsock(Index).GetData strData
    strData = strData & vbCrLf
    txtSaid.Text = txtSaid.Text & strData
    For i = Winsock.LBound + 1 To Winsock.UBound
        'There is an array of winsocks, winsock(0) is always to remain open to recieve
        'incoming connections, if it is accepted, then a new winsock is loaded
        Winsock(i).SendData strData
    Next i

End Sub


Let's say 2 clients were connected to the server. If I were to send a message from any client, the server would get it, but would only send the recieved messages to the most recent client to connect. I've shown this with a screenshot:

[url]http://tinyurl.com/goa7m

Here is the code I have from winsockvb.com showing how to load more winsock controls if more clients connect:

Private Sub winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
    Dim i As Integer
    Dim j As Boolean
    j = True
    
    For i = Winsock.LBound + 1 To Winsock.UBound
        If Winsock(i).State <> sckConnected Then
            Winsock(i).Accept RequestID
            j = False
            Exit For
        End If
    Next i
    
    If j = True Then
        Load Winsock(Winsock.UBound + 1)
        Winsock(Winsock.UBound).Accept RequestID
    End If
    
End Sub


I though that it might be disconnecting the clients for some reason, and as you can see in the screenshot I made those 6 command buttons that are coded like this:


Private Sub ws1_Click()
    Winsock(1).SendData "Test WS1"
End Sub

Private Sub ws2_Click()
    Winsock(2).SendData "Test WS2"
End Sub

Private Sub ws3_Click()
    Winsock(3).SendData "Test WS3"
End Sub


Say clients 1 and 2 were connected, and only client 2 was getting all the data the server was supposed to be sending all clients. As soon as I hit the client 1 button to test if it's still connected, all the data that was supposed to be sent earlier gets sent (or recieved) when I hit the test button. I've gone over my code several times, and I've searched multiple forums and eangines, only to learn that searching for specific problems is pretty useless.

I think I have shown everything that one would need to know what is going on and possibly know a fix. (If not please tell me what needs to be added) Any help is greatly appreciated!

01-10-2006 at 10:09 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Network : Need help connecting multiple clients in chat program
Previous Topic (Networking Router)Next Topic (Introduction to Networking Free Download) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2016 Andrea Tincaniborder