Results 1 to 5 of 5

Thread: TCP/IP chat program question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    Phoenix
    Posts
    87

    Question

    Hey All,
    I'm a semi-TCP/IP newbie and I've been trying to write a TCP/IP based chat server in VB using the WinSock control.
    I started my project based on the short tutorial on WinSock here on VB-World. I guess
    all it really is a TCP/IP connection manager. Listen for connection requests, allocate
    another winsock control, set it to 'listen', ad infinitum.

    The chat clients passes as part of the data stream which user it wants to send data to.
    So i just parse that off, perform a look up of which winsock relates to that user and
    then send the data.

    The problem is after I allocate a couple connections, only the latest connection allocated
    will recieve messages. None of the previous connections will recieve data.

    Can the TCP/IP in VB only listen to 1 connection at a time? Any ideas why only the latest
    connection will recieve data?

    Sorry I dont have any code to post at the moment, I'm at work

    Is what I'm trying to do even possible in VB?

    Thanks for any ideas...

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Your best bet is to put each "Client" into an array containing the winsock index they are on . Then when a msg comes in that's is ment for all clients to recieve you simply parse your array for the sock index . I hope your good with arrays because you'll have to catch the index in the winsock_Disconnect event to remove them from your array otherwise you'll error out trying to send data on a sock thats no longer connected .

    Best of Luck ,

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    87
    Sounds like each time you are trying to put the new socket in a listen state.

    1 socket should be assigned as a listening socket.
    another socket (array) handles assigned connections.

    Code:
    Private Sub Form_Load()
        
        'Start a socket listening for connection requests
        sckListen.LocalPort = 100
        sckListen.Listen
    
    End Sub
    
    Private Sub sckListen_ConnectionRequest(ByVal requestID As Long)
    
        Dim iIndex          As Integer
        
        'Get a the next free socket index
        iIndex = UBound(sckConnections) + 1
        
        'Load a new socket to handle the new incoming connection
        Load sckConnections(iIndex)
        
        'Pass the 'socket handle' the new socket so it can handle the incoming data
        sckConnections(iIndex).Accept requestID
        
    End Sub

    Hope this helps

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Violenza

    This should answer your question:
    FIX: Winsock Control SendData Only Works Over the Latest Connection

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    Phoenix
    Posts
    87
    ive got my app working great now thanks to you guys =)

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