Oppure

Loading
10/07/09 8:07
GoLDBeRG
eh ma è dove inizia a leggere il socket il problema....
se tu assegni a tutti 0 all'inizio facciamo un esempio...
socket
socket 2 e socket 3
tutti e tre da offset 0....

socket 1 fa il primo byte
intanto anche socket 2 e tre avevano fatto il primo byte...
cosi passano entrambi al 2... ma anche il primo è passato al secondo... e mentre il primo passa al 2 uno degli altri 2 sarà passato al terzo....non funziona cosi... ogni socket deve scaricare la sua e solo la sua partizione di file....in modo da non interferire con l'offset degli altri....
cmq la dimensione del file si puo sapere a priori guarda


Sample

Below is a sample conversation between an HTTP client and an HTTP server running on example.com, port 80.

Client request (followed by a blank line, so that request ends with a double newline, each in the form of a carriage return followed by a line feed):

GET /index.html HTTP/1.1
Host: example.com


The "Host" header distinguishes between various DNS names sharing a single IP address, allowing name-based virtual hosting. While optional in HTTP/1.0, it is mandatory in HTTP/1.1.

Server response (followed by a blank line and text of the requested page):

HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8

The ETag (entity tag) header is used to determine if a cached version of the requested resource is identical to the current version of the resource on the server. Content-Type specifies the Internet media type of the data conveyed by the http message, while Content-Length indicates its length in bytes. The HTTP/1.1 webserver publishes its ability to respond to requests for certain byte ranges of the document by setting the header Accept-Ranges: bytes. This is useful if the client needs to have only certain portions[8] of a resource sent by the server, which is called byte serving. When Connection: close is sent in a header, it means that the web server will close the TCP connection immediately after the transfer of this package.


solo che non capisco perche io non ricevo quella roba dove ce il content lenght... a me quello serve.....
aaa
10/07/09 8:35
GoLDBeRG
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()
        sock = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        sock.Connect("colossus.altervista.org", 80)
        ' sock.Connect("www.artfiles.org", 80)
        down = New NetworkStream(sock)
        ' send("OPTIONS http://www.artfiles.org/knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN.iso")
        sock.BeginReceive(altro, 0, altro.Length, SocketFlags.None, New AsyncCallback(AddressOf ricevi), Nothing)
        send("HEAD http://colossus.altervista.org/file/Colossus.zip")
    End Sub

    Public Sub send(ByVal data As String)
        If data.EndsWith(vbCrLf) = False Then
            data &= vbCrLf
        End If
        Dim byt() As Byte = Encoding.ASCII.GetBytes(data)
        down.Write(byt, 0, byt.Length)
        down.Flush()
    End Sub

    Public Sub ricevi(ByVal ar As IAsyncResult)
        Dim int As Integer = sock.EndReceive(ar)
        If int > 1 Then
            Dim str As String = Encoding.ASCII.GetString(altro)
            MsgBox(str)
            sock.BeginReceive(altro, 0, altro.Length, SocketFlags.None, New AsyncCallback(AddressOf ricevi), Nothing)
        Else
            Exit Sub
        End If
    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

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim p As New conn
        Dim thr As New Thread(AddressOf p.scarica)
        thr.Start()
    End Sub
End Class


vedi questa stringa qui


   send("HEAD http://colossus.altervista.org/file/Colossus.zip")


al posto di HEAD se metti GET ti manda direttamente il file... quindi ricevi caratteri illeggibili... se metti OPTIONS da Errore... se metti HEAD ti sputa in faccia.... ci deve essere un comando per farmi dire quanto è grande.....
aaa
10/07/09 9:03
riseofapocalypse
Leggi un po' qua: it.wikipedia.org/wiki/…
In pratica per utilizzare il metodo GET si fa così:
Send(System.Text.Encoding.ASCII.GetBytes("GET http://colossus.altervista.org/file/Colossus.zip HTTP/1.1" & vbNewLine & vbNewLine))

Ora il messaggio di errore è diverso: 400 Bad Request
aaa
10/07/09 11:44
GoLDBeRG
richiesta errata? :|
aaa
10/07/09 12:01
riseofapocalypse
Beh almeno adesso non dice che il comando è inutilizzabile! :rotfl: però dovrebbe funzionare, secondo le indicazioni di Wikipedia... :yup:
aaa
10/07/09 12:20
GoLDBeRG
stavo pensando.... visto che col socket pure l'apache fa il cretino e non ci dice quanto è grande il file... se usiamo al posto dei sock i webclient? pero' sempre tanti come fossero socket.....
aaa
10/07/09 12:41
riseofapocalypse
Non è colpa del Socket, anche usando Telnet da gli stessi problemi :yup:

Ho appena provato con il WebClient e indovina un po'...il Server accetta la richiesta! Evidentemente la Microsoft ha fatto in modo che i Socket non siano puri! -.-"

CI SONO RIUSCITO! :rotfl:
        Dim wc As New Net.WebClient
        Dim b1() As Byte = wc.Encoding.GetBytes("GET /file/Colossus.zip HTTP/1.1" & vbNewLine & vbNewLine)
        wc.OpenWrite("http://colossus.altervista.org/").Write(b1, 0, b1.Length)
        Dim s2 As IO.Stream = wc.OpenRead("http://colossus.altervista.org/file/Colossus.zip")
        Dim b2 As New List(Of Byte)
        For i As Integer = 0 To wc.ResponseHeaders(Net.HttpResponseHeader.ContentLength) - 1
            b2.Add(s2.ReadByte)
        Next
        IO.File.WriteAllBytes("C:\casa.zip", b2.ToArray)

wc.ResponseHeaders(Net.HttpResponseHeader.ContentLength) è il numero di byte! :D ora possiamo trovare il modo di dividere il file :k:
Ultima modifica effettuata da riseofapocalypse 11/07/09 8:31
aaa
10/07/09 17:19
GoLDBeRG
ti ha mai detto nessuno che sei un genio ragazzo mio :pat:
aaa