Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - HTTPwebrequest
Forum - C# / VB.NET - HTTPwebrequest - Pagina 5

Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 11:49
Sabato, 11/07/2009
fai una classe chiamata conn.vb e mettici dentro...

Codice sorgente - presumibilmente VB.NET

  1. Imports System
  2. Imports System.IO
  3. Imports System.Net
  4. Imports System.Net.Sockets
  5. Imports System.Threading
  6. Imports System.Text
  7.  
  8. Public Class conn
  9.  
  10.     Public down As NetworkStream
  11.     Public sock As Socket
  12.     Public buff(8192) As Byte
  13.     Public start As Long
  14.     Public ferma As Long
  15.     Public memo As Long
  16.  
  17.     Public Sub scarica()
  18.         sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  19.         sock.Connect("www.artfiles.org", 80)
  20.         down = New NetworkStream(sock)
  21.         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)
  22.         sock.BeginReceive(buff, start, buff.Length, SocketFlags.None, New AsyncCallback(AddressOf anco), Nothing)
  23.         down.Write(byt, 0, byt.Length)
  24.         down.Flush()
  25.     End Sub
  26.  
  27.     Public Sub anco(ByVal ar As IAsyncResult)
  28.         Dim int As Integer = sock.EndReceive(ar)
  29.         If int < 1 Then
  30.             End
  31.         End If
  32.         impo.quanti += int
  33.         memo += int
  34.         If memo > ferma Then
  35.             Exit Sub
  36.         End If
  37.         sock.BeginReceive(buff, memo, buff.Length, SocketFlags.None, New AsyncCallback(AddressOf anco), Nothing)
  38.     End Sub
  39. End Class



poi fai un form e ci metti dentro sta robaccia

Codice sorgente - presumibilmente VB.NET

  1. Imports System
  2. Imports System.IO
  3. Imports System.Net
  4. Imports System.Net.Sockets
  5. Imports System.Threading
  6. Imports System.Text
  7.  
  8. Public Class download
  9.  
  10.     Public filegen As Long
  11.     Dim sock As Socket
  12.     Dim down As NetworkStream
  13.     Dim altro(1024) As Byte
  14.  
  15.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  16.         Dim h As New Thread(AddressOf vedi)
  17.         h.Start()
  18.     End Sub
  19.  
  20.     Public Sub vedi()
  21.         Dim wc As New Net.WebClient
  22.         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)
  23.         wc.OpenWrite("http://www.artfiles.org/").Write(b1, 0, b1.Length)
  24.         wc.OpenRead("http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso")
  25.         For Each asd As String In wc.ResponseHeaders
  26.             If IsNumeric(wc.ResponseHeaders.Item(asd)) Then
  27.                 filegen = wc.ResponseHeaders.Item(asd)
  28.             End If
  29.         Next
  30.         Dim conto As Int16 = 10
  31.         While ((filegen Mod conto) <> 0)
  32.             conto += 1
  33.         End While
  34.         Dim parte As Long = filegen / conto
  35.         For a As Integer = 0 To conto - 2
  36.             Dim f As New conn
  37.             f.start = parte * a
  38.             f.ferma = f.start + parte
  39.             Dim g As New Thread(AddressOf f.scarica)
  40.             g.Start()
  41.         Next
  42.     End Sub
  43.  
  44.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  45.         Try
  46.             Label2.Text = Int((impo.quanti / 1024) / 5)
  47.             impo.quanti = 0
  48.         Catch ex As Exception
  49.  
  50.         End Try
  51.     End Sub
  52. 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?

PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 12:26
Sabato, 11/07/2009
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..................

PM Quote
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 12:59
Sabato, 11/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

  1. Imports System.Net
  2. Imports System.Net.Sockets
  3. Imports System.Text
  4. Imports System.Threading
  5. Public Class Form1
  6.     Dim numerosocket As Integer = 5
  7.     Dim parti As New List(Of Integer)
  8.     Structure downthread
  9.         Dim size, id As Decimal
  10.     End Structure
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.         Dim wc As New WebClient
  13.         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)
  14.         wc.OpenWrite("http://www.artfiles.org/").Write(b, 0, b.Length)
  15.         wc.OpenRead("http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso")
  16.         Dim grandezza As Decimal = wc.ResponseHeaders(HttpResponseHeader.ContentLength)
  17.         For i As Integer = 0 To numerosocket - 1
  18.             If i = numerosocket - 1 Then
  19.                 parti.Add(grandezza Mod (numerosocket - 1))
  20.             Else
  21.                 parti.Add(Int(grandezza / (numerosocket - 1)))
  22.             End If
  23.             Dim t As New Thread(AddressOf scarica)
  24.             t.Start(New downthread With {.size = parti(i), .id = i})
  25.         Next
  26.     End Sub
  27.     Sub scarica(ByVal parte As downthread)
  28.         Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  29.         s.Connect("www.artfiles.org", 80)
  30.         Dim ns As New NetworkStream(s)
  31.         Dim b As New List(Of Byte)
  32.         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))
  33.         ns.Write(b.ToArray, 0, b.Count)
  34.         ns.Seek(parte.id * parte.size, IO.SeekOrigin.Begin)
  35.         b.Clear()
  36.         For i As Integer = 0 To parte.size - 1
  37.             b.Add(ns.ReadByte)
  38.             Application.DoEvents()
  39.         Next
  40.         MsgBox(Encoding.ASCII.GetString(b.ToArray))
  41.     End Sub
  42. 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: http://msdn.microsoft.com/it-it/library/system.net.sockets ...
Per cosa esiste se genera sempre un'eccezione? -.-"

Ultima modifica effettuata da riseofapocalypse il 11/07/2009 alle 13:05
PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 13:25
Sabato, 11/07/2009
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.....

PM Quote
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 13:53
Sabato, 11/07/2009
L'unica soluzione che mi viene in mente è scorrere manualmente lo Stream in questo modo:
Codice sorgente - presumibilmente VB.NET

  1. For i As Integer = 0 To posizione - 1
  2.           s.ReadByte()
  3.      Next


Ma sarebbe un tantino controproducente :yup:

Ultima modifica effettuata da riseofapocalypse il 11/07/2009 alle 13:54
PM Quote
Avatar
GoLDBeRG (Ex-Member)
Expert


Messaggi: 331
Iscritto: 19/12/2005

Segnala al moderatore
Postato alle 17:54
Sabato, 11/07/2009
e ora come facciamo......proviamo ad aprire un altro post chiedendo come posizionare il puntatore dello stream al punto voluto?

PM Quote
Avatar
riseofapocalypse (Ex-Member)
Pro


Messaggi: 150
Iscritto: 08/07/2009

Segnala al moderatore
Postato alle 20:50
Sabato, 11/07/2009
Direi di si, questa discussione sta diventando un po' troppo lunga! :rotfl:

PM Quote
Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo