Ho un problema nell'uploadare i file su di una macchina remota. I winsock sono connessi; riesco ad inviare al server le informazioni per quanto riguarda il file (nome + estensione, dimensione). Il problema è che l'upload si blocca non invia niente, soltanto i 4 kb iniziali, e non restituisce alcun errore. Molto probabilmente è sbagliato il mio modo di inviare, se qualcuno mi potrebbe dare una dritta. Utilizzo una progressbar per monitorare il progresso, lo denominata "bar". Per l'upload uso due winsock. Uno per ricevere le informazioni e l'altro per ottenere i bite del file.

Client:


codice:
Private percorso As String
Private nomefile As String
Private dimensione As Long
Private handle As Integer
Private bites(4000) As Byte         

Private Sub winsock_DataArrival(ByVal bytesTotal As Long)

Dim data As String
winsock.GetData data

If data = "start" Then
handle = FreeFile
Open percorso For Binary As handle
Get handle, , bites
winsock2.SendData bites
End If

If data = "inviami" Then
Get handle, , bites
winsock2.SendData bites
End If

If data = "finish" Then
Close handle
End If

End Sub

Server:


codice:
Private dimensione As Long
Private nomefile As String
Private handle As Integer


Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim data As String
winsock.GetData data


If Left(data, 3) = "ini" Then
dimensione = Right(data, Len(data) - 3)
End If


If Left(data, 4) = "imus" Then
nomefile = Right(data, Len(data) - 4)
Form2.Caption = nomefile & " " & dimensione
End If


If Left(data, 5) = "ercus" Then
handle = FreeFile
Open "C:\" & nomefile For Binary As handle
DoEvents
winsock.SendData "start"  ' QUA INIZIA LA PARTE DI CODICE DELL'UPLOAD
bar.Max = dimensione
End If


End Sub

codice:
Private Sub winsock2_DataArrival(ByVal bytesTotal As Long)
Dim data() As Byte
winsock2.GetData data

If UBound(data) + LOF(handle) + 1 >= dimensione Then
ReDim Preserve data(dimensione - LOF(handle) - 1)
Put handle, , data
bar.Value = LOF(handle)
DoEvents
Close handle
winsock.SendData "finish"

Else

Put handle, , data
winsock.SendData "inviami"
bar.Value = LOF(handle)

End If

End Sub