Results 1 to 7 of 7

Thread: First piece of data not sending?

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    First piece of data not sending?

    Ok, I have a constantly open port which the client connects to, and then is redirected to a new socket. This works fine, but when I set up this new connection, I want to send the index of my winsock array back to the client, which I do right after the .accept method, but it doesn't send (or it isn't received, can't really tell which). I'm making sure they're connected before executing this, and all other instances of senddata work fine after, what's wrong?

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

    Re: First piece of data not sending?

    Most likely, you are sending the data before the connection process has finished. I would try using the Connect event to send the index. Personally, I have never tried using the Connect event on the server side because my servers do not send anything immediately after connecting. They only respond to requests from the client(s).

    I'm curious as to why you are sending the client the index of the winsock control. Are you, perhaps, under the impression that the client needs to know which control it is connected to?

    If you do in fact need to send the index, try this:
    VB Code:
    1. Private Sub Winsock1_Connect(Index As Integer)
    2.   Winsock1.SendData Index
    3. End Sub
    It will fire when the connection has completed for the control indicated by the value of Index.

  3. #3

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: First piece of data not sending?

    Sorry, that doesn't work either.

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: First piece of data not sending?

    In fact, my _connect method isn't even invoked.

    Can you see anything wrong with my code?

    VB Code:
    1. Private Sub sckSendConnection_ConnectionRequest(ByVal requestID As Long)
    2.   sckSendConnection.Close
    3.   Dim I As Integer
    4.   For I = 0 To sckConnections.UBound - 1
    5.     If sckConnections(I).State = sckListening Then
    6.       sckConnections(I).Close
    7.       sckConnections(I).Accept requestID
    8.       sckSendConnection.Listen
    9.       Exit Sub
    10.     End If
    11.   Next I
    12.   Load sckConnections(sckConnections.UBound + 1)
    13.   I = sckConnections.UBound - 1
    14.   sckConnections(I + 1).LocalPort = sckConnections(I).LocalPort + 1
    15.   sckConnections(I + 1).Listen
    16.  
    17.   sckConnections(I).Close
    18.   sckConnections(I).Accept requestID
    19.   Do Until sckConnections(I).State = sckConnected
    20.     DoEvents
    21.   Loop
    22.  
    23.   sckSendConnection.Listen
    24. End Sub

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

    Re: First piece of data not sending?

    I have to confess that I have never seen anyone try to do what you are doing. I'm not sure it is even going to work. It looks like you have a single listener (sckSendConnection) and an array of winsock controls, all of which may or may not be listening as well. I'm really not sure what you are trying to do.

    Your listener should be the first control in the array (index = 0) and connections should be accepted on one of the controls (index = 1 and up) that is closed.

    Take a look at the ConnectionRequest code that I posted earlier today on
    http://www.vbforums.com/showthread.p...19#post1979519

  6. #6

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: First piece of data not sending?

    I don't really understand, why does it matter? The servers always connect with the client just fine, and all data sent that wasn't in the listening server's sub send just fine. Either way, I suppose I'll try it...

  7. #7

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: First piece of data not sending?

    Found the problem, apparently closing and listening the listener socket was screwing with something, anyone know why this is?
    Here's the revised code:
    VB Code:
    1. Private Sub sckSendConnection_ConnectionRequest(ByVal requestID As Long)
    2.  
    3.   Dim I As Integer
    4.   For I = 0 To sckConnections.UBound - 1
    5.     If sckConnections(I).State = sckListening Or sckConnections(I).State = sckClosing Then
    6.       sckConnections(I).Close
    7.       sckConnections(I).Accept requestID
    8.       sckConnections(I).SendData "PORT" & Chr(1) & CStr(I) & Splitter
    9.       Exit Sub
    10.     End If
    11.   Next I
    12.   'load a new one
    13.   Load sckConnections(sckConnections.UBound + 1)
    14.   'and set I to ubound -1
    15.   I = sckConnections.UBound - 1
    16.   sckConnections(I + 1).LocalPort = sckConnections(I).LocalPort + 1
    17.   sckConnections(I + 1).Listen
    18.   'connect
    19.   sckConnections(I).Close
    20.   sckConnections(I).Accept requestID
    21.   sckConnections(I).SendData "PORT" & Chr(1) & CStr(I) & Splitter
    22.  
    23. End Sub

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