Ok here's the problem.. Im sending several files (unknown amount) from the server to a client. But during the send, it will stop with an error that says "Connection is aborted due to timeout or other failure".

After receiving that error i added in some Delay's thinking maybe its a timeout, but even with just a single 1 second delay, i get this message: "Connection is forcefully rejected".

So its either going to quick or too slow.. I cant get it perfect so i need to do something different.

Im using the code from this thread http://www.vbforums.com/showthread.php?t=377648

I couldnt figure out how to get the thing to send multiple files back to back, so the way ive got it setup, it will load each file path and name into a text file line by line, and get it line by line and hit the send button. Once its done and the file and winsock are closed, it hits that button again to send the next..

I already successfully did this in the control panel of my program to update everything, but going the other way it just wont work properly..

When the program starts up, it loads the splash screen and connects to the server with Winsock1. It then sends the version of the current exe file to the server and checks it with the stored EXE in the update folder on the server computer. If there's a new version it sends back information to the client letting it know it needs an update and the server closes and launches the patcher (not necessary but i'll explain later if needed). The client computer does the same, downloads the new exe and replaces it, then runs it again.

If there isnt a new version of the program, then it sends back the file count to the client so the client can calculate the percent completed, then sends "Start" back to the server and from there it will start sending the files.

The client computer has a 2nd winsock control on it thats already Listening for a connection, and when the server receives "Start" it goes through and runs the code to start sending each file 1 by 1, the server also has 2 winsock controls for this. Im testing it locally on this computer for now until its ready, then i'll put the server app on the server. So for now, everything is set at 127.0.0.1, Here's a bunch of hopefully helpful code:

Client Side Code
I'll only show the code for the 2nd winsock control that is supposed to receive the file, since the first one works properly, and this is the section with the errors.

Code:
Private Sub SckReceiveFile_DataArrival(Index As Integer, ByVal bytesTotal As Long)

    Dim sData As String, Pos As Long, Pos2 As Long
    
    SckReceiveFile(Index).GetData sData, vbString
    
    If sData <> "®±Finished¢¤" Then
      If Clients(Index).FileSize = 0 And InStr(1, sData, ":") > 0 Then
          Pos = InStr(1, sData, ",")
          
          Clients(Index).FileSize = Val(left(sData, Pos - 1))
          Pos2 = InStr(Pos, sData, ":")
          Clients(Index).FileName = Mid(sData, Pos + 1, (Pos2 - Pos) - 1)
          
          Clients(Index).FileNum = FreeFile
          Select Case Clients(Index).FileName
            Case Is = "q.dw"
               lblStatus.Caption = "Updating Basic Questions"
               Open App.Path & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
            Case Is = "JobSpec.dw"
               lblStatus.Caption = "Updating Job Specific Questions"
               Open App.Path & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
               ProgressBar.Value = ProgressBar.Value + (100 / FileCount)
            Case Is = "Prod.dw"
               lblStatus.Caption = "Updating Product Data"
               Open App.Path & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
               ProgressBar.Value = ProgressBar.Value + (100 / FileCount)
            Case Is = "ProdPrice.dw"
               lblStatus.Caption = "Updating Pricing Information"
               Open App.Path & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
               ProgressBar.Value = ProgressBar.Value + (100 / FileCount)
            Case Is = "systemdw.dat"
               lblStatus.Caption = "Updating Global Settings"
               Open Environ("windir") & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
               ProgressBar.Value = ProgressBar.Value + (100 / FileCount)
            Case Else
               ImgCount = ImgCount + 1
               lblStatus.Caption = "Updating Product Images (" & ImgCount & " of " & FileCount - 4 & ")"
               Open App.Path & "\Images\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum
               ProgressBar.Value = ProgressBar.Value + (100 / FileCount)
          End Select
                    
          sData = Mid(sData, Pos2 + 1)
          
          Me.lstConnections.ListItems(Index + 1).SubItems(3) = Clients(Index).FileName
          Else
            frmMain.Show
            Unload Me
      End If
      
      If Len(sData) > 0 Then
          Clients(Index).BytesReceived = Clients(Index).BytesReceived + Len(sData)
          Put Clients(Index).FileNum, , sData
          
          PicShowPercentage picProgress, Loc(Clients(Index).FileNum) / CDbl(LOF(Clients(Index).FileNum))

          If Clients(Index).BytesReceived >= Clients(Index).FileSize Then
              SckReceiveFile_Close Index
          End If
      End If
   End If
End Sub
Under 'Close', where it has the code for the end of the file i have it set to listen again just as it finishes, so that its ready for the next file.

Server Side Code

Once winsock is done connecting, it hits the connect button for me which is this code:
Code:
Private Sub cmdSendFiles_Click()
Dim Buffer() As Byte, P As Long
Dim CurFile As String
         Delay 1
         Input #10, CurFile
         txtFileName.Text = CurFile
         Select Case CurFile
            Case Is = App.Path & "\q.dw"
               Label1.Caption = "Sending Basic Questions"
               SendFile txtFileName.Text
            Case Is = App.Path & "\JobSpec.dw"
               Label1.Caption = "Sending Job Specific Questions"
               SendFile txtFileName.Text
            Case Is = App.Path & "\Prod.dw"
               Label1.Caption = "Sending Products"
               SendFile txtFileName.Text
            Case Is = App.Path & "\ProdPrice.dw"
               Label1.Caption = "Sending Prices"
               SendFile txtFileName.Text
            Case Is = Environ("windir") & "\systemdw.dat"
               Label1.Caption = "Sending Global Settings"
               SendFile txtFileName.Text
            Case Else
               Label1.Caption = "Sending Product Images"
               SendFile txtFileName.Text
         End Select
End Sub
The SendFile sub will connect to the client computer, and when it connects, it runs this code:
Code:
Private Sub SckSendFile_Connect()
    Dim Buffer() As Byte, P As Long
    lblSendFile.Caption = "Connected"
    SendIdle = False
    If Finished = False Then
      Delay (1)
      iFileNum = FreeFile
      Open sFileName For Binary Access Read Lock Write As iFileNum
      
      ReDim Buffer(lngMIN(LOF(iFileNum), PacketSize) - 1)
      Get iFileNum, , Buffer ' read data
      
      SckSendFile.SendData CStr(LOF(iFileNum)) & ","   ' send the file size
      P = InStrRev(sFileName, "\")
      SckSendFile.SendData Mid(sFileName, P + 1) & ":" ' send the file name
      SckSendFile.SendData Buffer                      ' send first packet
      Else
         SckSendFile.SendData "®±Finished¢¤"
         SckSendFile.Close
         Finished = False
         Delay 1
         SendIdle = True
         CheckRestart
         SckSendFile.Listen
         Label1.Caption = "Listening on port " & Winsock1.LocalPort
         sFileName = ""
         iFileNum = 0
   End If
End Sub
Im not sure what the timer does since i dont understand the code for sending the files. But here's some code that uses it, i think its whats sending the file somehow:
Code:
Private Sub SckSendFile_SendComplete()
    ' can't call SendData here, so enable timer to do it...
    tmrSendFile.Enabled = False
    tmrSendFile.Interval = 1
    tmrSendFile.Enabled = True
End Sub
Code:
Private Sub SckSendFile_Close()
    lblSendFile.Caption = "Disconnected"
    tmrSendFile.Enabled = False
    tmrSendFile.Interval = 0
    
    Close iFileNum ' close file
    iFileNum = 0 ' set file number to 0, timer will exit if another timer event
    
    SckSendFile.Close
    
    cmdSendFile.Caption = "&Send File"
    PicShowPercentage Me.picProgress, 0
    lblProgress.Caption = "0.00% Done"
    
    If Not EOF(10) Then
      cmdSendFiles_Click
      Else
         Close #10
         Label1.Caption = "Finished Updating Server!"
         SendIdle = True
         cmdListen_Click
         Finished = True
    End If
End Sub
Ok, not sure what else to show you guys, so if you need anything else lemme know.

Ive been trying to fix this issue for 3 days now, ive put 10~12 hours of work on this each day and still im nowhere... Ive recoded it several different ways using just the 1 winsock for doing everything, ive split it into 2 which its currently at now, and all kinds of other stuff.. I cant get it to work!!

PLEASE HELP!!!!!!!