GoLDBeRG (Ex-Member)
Expert
Messaggi: 331
Iscritto: 19/12/2005
|
fai una classe chiamata conn.vb e mettici dentro...
Codice sorgente - presumibilmente VB.NET |
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
Codice sorgente - presumibilmente VB.NET |
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?
|
|
GoLDBeRG (Ex-Member)
Expert
Messaggi: 331
Iscritto: 19/12/2005
|
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..................
|
|
riseofapocalypse (Ex-Member)
Pro
Messaggi: 150
Iscritto: 08/07/2009
|
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ì:
Codice sorgente - presumibilmente VB.NET |
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
|
Ultima modifica effettuata da riseofapocalypse il 11/07/2009 alle 13:05 |
|
GoLDBeRG (Ex-Member)
Expert
Messaggi: 331
Iscritto: 19/12/2005
|
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.....
|
|
riseofapocalypse (Ex-Member)
Pro
Messaggi: 150
Iscritto: 08/07/2009
|
L'unica soluzione che mi viene in mente è scorrere manualmente lo Stream in questo modo:
Codice sorgente - presumibilmente VB.NET |
For i As Integer = 0 To posizione - 1 s.ReadByte() Next
|
Ma sarebbe un tantino controproducente
Ultima modifica effettuata da riseofapocalypse il 11/07/2009 alle 13:54 |
|
GoLDBeRG (Ex-Member)
Expert
Messaggi: 331
Iscritto: 19/12/2005
|
e ora come facciamo......proviamo ad aprire un altro post chiedendo come posizionare il puntatore dello stream al punto voluto?
|
|
riseofapocalypse (Ex-Member)
Pro
Messaggi: 150
Iscritto: 08/07/2009
|
Direi di si, questa discussione sta diventando un po' troppo lunga!
|
|