Oppure

Loading
10/07/09 19:10
riseofapocalypse
Muhahaha grazie :rotfl: avevamo la soluzione sotto gli occhi :D

Ti informo che oggi, 11 Luglio 2009, quando cerco di ottenere:
wc.ResponseHeaders(Net.HttpRequestHeader.ContentLength)

Mi da errore! -_-"
InvalidOperationException non è stata gestita.
Questo insieme contiene intestazioni di risposta. Non può contenere l'intestazione di richiesta specificata.


Che stupido sono stato! Certo che non funzionava, utilizzavo un RequestHeader per ottenere il RespondeHeader! Invece è così:
wc.ResponseHeaders(Net.HttpResponseHeader.ContentLength)

:rotfl:
Ultima modifica effettuata da riseofapocalypse 11/07/09 8:27
aaa
11/07/09 9:49
GoLDBeRG
fai una classe chiamata conn.vb e mettici dentro...

Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text

Public Class conn

    Public down As NetworkStream
    Public sock As Socket
    Public buff(8192) As Byte
    Public start As Long
    Public ferma As Long
    Public memo As Long

    Public Sub scarica()
        sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        sock.Connect("www.artfiles.org", 80)
        down = New NetworkStream(sock)
        Dim byt() As Byte = Encoding.ASCII.GetBytes("GET http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso HTTP/1.1" & vbCrLf & vbCrLf)
        sock.BeginReceive(buff, start, buff.Length, SocketFlags.None, New AsyncCallback(AddressOf anco), Nothing)
        down.Write(byt, 0, byt.Length)
        down.Flush()
    End Sub

    Public Sub anco(ByVal ar As IAsyncResult)
        Dim int As Integer = sock.EndReceive(ar)
        If int < 1 Then
            End
        End If
        impo.quanti += int
        memo += int
        If memo > ferma Then
            Exit Sub
        End If
        sock.BeginReceive(buff, memo, buff.Length, SocketFlags.None, New AsyncCallback(AddressOf anco), Nothing)
    End Sub
End Class



poi fai un form e ci metti dentro sta robaccia

Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text

Public Class download

    Public filegen As Long
    Dim sock As Socket
    Dim down As NetworkStream
    Dim altro(1024) As Byte

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim h As New Thread(AddressOf vedi)
        h.Start()
    End Sub

    Public Sub vedi()
        Dim wc As New Net.WebClient
        Dim b1() As Byte = wc.Encoding.GetBytes("Get http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso HTTP/1.1" & vbNewLine & vbNewLine)
        wc.OpenWrite("http://www.artfiles.org/").Write(b1, 0, b1.Length)
        wc.OpenRead("http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso")
        For Each asd As String In wc.ResponseHeaders
            If IsNumeric(wc.ResponseHeaders.Item(asd)) Then
                filegen = wc.ResponseHeaders.Item(asd)
            End If
        Next
        Dim conto As Int16 = 10
        While ((filegen Mod conto) <> 0)
            conto += 1
        End While
        Dim parte As Long = filegen / conto
        For a As Integer = 0 To conto - 2
            Dim f As New conn
            f.start = parte * a
            f.ferma = f.start + parte
            Dim g As New Thread(AddressOf f.scarica)
            g.Start()
        Next
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            Label2.Text = Int((impo.quanti / 1024) / 5)
            impo.quanti = 0
        Catch ex As Exception

        End Try
    End Sub
End Class



sock.BeginReceive(buff, start, buff.Length, SocketFlags.None, New AsyncCallback(AddressOf anco), Nothing)

a questa riga il maledetto vb da errore sull'offset... dice che è troppo grande..... ma io gli devo far leggere solo dal punto specificato... e si fa con quello..... come glielo faccio capire?
aaa
11/07/09 10:26
GoLDBeRG
nono aspetta che errore madornale.... offset è l'indice dell'array iniziale dove inizierà a salvare byte..... che cacchio stavo dicendo... pero' ora... che mi sono corretto... nn so proprio come dirgli che deve leggere dal byte numero es 500 e non dall'inizio..................
aaa
11/07/09 10:59
riseofapocalypse
Sinceramente non riesco a capire dov'è l'errore, a me si chiude il programma senza dare segnalazioni! Comunque io ho preso spunto dal tuo codice e ho fatto così:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Public Class Form1
    Dim numerosocket As Integer = 5
    Dim parti As New List(Of Integer)
    Structure downthread
        Dim size, id As Decimal
    End Structure
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim wc As New WebClient
        Dim b() As Byte = Encoding.ASCII.GetBytes("GET http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso HTTP/1.1" & vbNewLine & vbNewLine)
        wc.OpenWrite("http://www.artfiles.org/").Write(b, 0, b.Length)
        wc.OpenRead("http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso")
        Dim grandezza As Decimal = wc.ResponseHeaders(HttpResponseHeader.ContentLength)
        For i As Integer = 0 To numerosocket - 1
            If i = numerosocket - 1 Then
                parti.Add(grandezza Mod (numerosocket - 1))
            Else
                parti.Add(Int(grandezza / (numerosocket - 1)))
            End If
            Dim t As New Thread(AddressOf scarica)
            t.Start(New downthread With {.size = parti(i), .id = i})
        Next
    End Sub
    Sub scarica(ByVal parte As downthread)
        Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        s.Connect("www.artfiles.org", 80)
        Dim ns As New NetworkStream(s)
        Dim b As New List(Of Byte)
        b.AddRange(Encoding.ASCII.GetBytes("GET http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso HTTP/1.1" & vbNewLine & vbNewLine))
        ns.Write(b.ToArray, 0, b.Count)
        ns.Seek(parte.id * parte.size, IO.SeekOrigin.Begin)
        b.Clear()
        For i As Integer = 0 To parte.size - 1
            b.Add(ns.ReadByte)
            Application.DoEvents()
        Next
        MsgBox(Encoding.ASCII.GetString(b.ToArray))
    End Sub
End Class

Però al momento in cui chiamo ns.Seek mi dice che il flusso non supporta le operazioni di ricerca!

Leggi qua a proposito del metodo Seek: msdn.microsoft.com/it-it/library/…
Per cosa esiste se genera sempre un'eccezione? -.-"
Ultima modifica effettuata da riseofapocalypse 11/07/09 11:05
aaa
11/07/09 11:25
GoLDBeRG
Attualmente non è supportato e genera sempre un'eccezione.

ma stiamo scherzando :| ma scusa.... ci metti un metodo che adesso mi serve per andare avanti e sto benedetto metodo non funziona mai? e io ora mi sparo nei testicoli? -.- ci deve esser eun altro modo per spostare il puntatore.....
aaa
11/07/09 11:53
riseofapocalypse
L'unica soluzione che mi viene in mente è scorrere manualmente lo Stream in questo modo:
     For i As Integer = 0 To posizione - 1
          s.ReadByte()
     Next

Ma sarebbe un tantino controproducente :yup:
Ultima modifica effettuata da riseofapocalypse 11/07/09 11:54
aaa
11/07/09 15:54
GoLDBeRG
e ora come facciamo......proviamo ad aprire un altro post chiedendo come posizionare il puntatore dello stream al punto voluto?
aaa
11/07/09 18:50
riseofapocalypse
Direi di si, questa discussione sta diventando un po' troppo lunga! :rotfl:
aaa