Results 1 to 2 of 2

Thread: Need help connecting multiple clients in chat program

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    1

    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:

    VB Code:
    1. Private Sub Winsock_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2.  
    3. Dim strData As String
    4. Dim i As Integer
    5.    
    6.     Winsock(Index).GetData strData
    7.     strData = strData & vbCrLf
    8.     txtSaid.Text = txtSaid.Text & strData
    9.     For i = Winsock.LBound + 1 To Winsock.UBound
    10.         'There is an array of winsocks, winsock(0) is always to remain open to recieve
    11.         'incoming connections, if it is accepted, then a new winsock is loaded
    12.         Winsock(i).SendData strData
    13.     Next i
    14.  
    15. 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:

    http://tinyurl.com/goa7m

    Here is the code I have from winsockvb.com showing how to load more winsock controls if more clients connect:
    VB Code:
    1. Private Sub winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
    2.     Dim i As Integer
    3.     Dim j As Boolean
    4.     j = True
    5.    
    6.     For i = Winsock.LBound + 1 To Winsock.UBound
    7.         If Winsock(i).State <> sckConnected Then
    8.             Winsock(i).Accept RequestID
    9.             j = False
    10.             Exit For
    11.         End If
    12.     Next i
    13.    
    14.     If j = True Then
    15.         Load Winsock(Winsock.UBound + 1)
    16.         Winsock(Winsock.UBound).Accept RequestID
    17.     End If
    18.    
    19. 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:

    VB Code:
    1. Private Sub ws1_Click()
    2.     Winsock(1).SendData "Test WS1"
    3. End Sub
    4.  
    5. Private Sub ws2_Click()
    6.     Winsock(2).SendData "Test WS2"
    7. End Sub
    8.  
    9. Private Sub ws3_Click()
    10.     Winsock(3).SendData "Test WS3"
    11. 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!

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Need help connecting multiple clients in chat program

    Do you have a project you can zip up and post here? It will be a lot easier to help you out that way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width