Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
12/09/10 15:25
salve, ho creato un programma che tramite socket invia e riceve file, il mio problema e che nel inviare il file, se sono sullo stesso pc lo ricevo esattamente identico( controllando byte x byte con un altro mio programma), mentre se lo ricevo via LAN, i pacchetti devono essere massimo di 4 byte l'uno se no non so per quale strano motivo arrivano inspiegabilmente diversi di poco solo alcuni pacchetti, e via internet e la stessa storia.. se il pacchetto e supera i 4 byte l'uno molto probabilmente arriva con dei byte diversi.. mentre se sono sullo stesso pc posso anche decidere di inviare e ricevere pacchetti da un mega e il file non viene moificato nemmeno di un byte dall'originale.

il codice per dividere e inviare il file è questo :

    Private Sub BWInvia_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWInvia.DoWork
        Cronometro.Start()
        Progresso = 0
        Dim File As File = FileAttuale()
        Dim Reader As New IO.FileStream(File.Percorso, IO.FileMode.Open)
        Dim esci As Boolean

        While Not esci = True
            Dim Bytes() As Byte
            If File.len - Progresso <= NBYTE Then
                If File.len - Progresso = 0 Then
                    Exit While
                End If
                ReDim Bytes(Math.Abs(Progresso - File.len))
                esci = True
            Else
                ReDim Bytes(NBYTE)
            End If
            Reader.Read(Bytes, 0, Bytes.Length - 1)
            While Not StreamFile.CanWrite = True
            End While
            StreamFile.Write(Bytes, 0, Bytes.Length - 1)
            BWInvia.ReportProgress(Progresso * 100 / File.len)
            Progresso += NBYTE
        End While
        Reader.Close()
        Cronometro.Reset()
    End Sub


mentre per la ricezione :

    Private Sub BWRicevi_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BWRicevi.DoWork
        Dim File As New IO.FileStream(RiceviFile.Percorso, IO.FileMode.Create)
        Progresso = 0
        Dim esci As Boolean
        Cronometro.Start()
        Do
            If ReceiverFile.Available Then
                Dim Bytes() As Byte
                If RiceviFile.len - Progresso <= NBYTE Then
                    ReDim Bytes(RiceviFile.len - Progresso)
                    esci = True
                Else
                    ReDim Bytes(NBYTE)
                    If Progresso = RiceviFile.len Then
                        esci = True
                    End If
                End If
                While Not StreamFile.CanRead = True
                    MsgBox("oi oi oi")
                End While
                StreamFile.Read(Bytes, 0, Bytes.Length - 1)
                File.Write(Bytes, 0, Bytes.Length - 1)
                BWRicevi.ReportProgress(Progresso * 100 / RiceviFile.len)
                Progresso += NBYTE
            End If
        Loop Until esci = True
        CambiaStato()
        File.Close()
        Cronometro.Reset()
    End Sub


spero di essermi spiegato :rofl:
grazie in anticipo