Download using socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Henrik

    #1

    Download using socket

    I want to download a file using socket programming (and
    not httprequest) but the DNS keeps giving me errors "IP
    is ok, but the attached data is not available"

    I am doing like this and the address is ok. does any one
    know what is wrong here?

    IPHostEntry lipa =
    Dns.Resolve("19 2.168.0.2/image.jpg");

    IPEndPoint lep = new
    IPEndPoint(lipa .AddressList[0], 80);
    Socket s = new Socket
    (lep.Address.Ad dressFamily,
    SocketType.Stre am,
    ProtocolType.Tc p);
    try
    {
    s.Connect(lep);
    }
    catch (Exception e)
    {
    Console.WriteLi ne
    ("Exception Thrown: " + e.ToString());
    }

    /*
    byte[] msg =
    Encoding.ASCII. GetBytes("This is a test");

    // Blocks until send
    returns.
    int i = s.Send(msg, 0,
    msg.Length, SocketFlags.Non e);
    */

    // Blocks until read
    returns.
    byte[] bytes = new byte
    [1024];
    byte[] inBuf = new byte
    [HttpBuffer];
    s.Receive(inBuf , 0,
    s.Available, SocketFlags.Non e);

    //Displays to the screen.
    //Console.WriteLi ne
    (Encoding.ASCII .GetString(byte s));
    s.Shutdown
    (SocketShutdown .Both);
    s.Close();


  • Jack Hanebach

    #2
    Re: Download using socket

    "Henrik" <hh@attento.d k> wrote in message
    news:0f2301c361 97$8795c000$a30 1280a@phx.gbl.. .[color=blue]
    > I want to download a file using socket programming (and
    > not httprequest) but the DNS keeps giving me errors "IP
    > is ok, but the attached data is not available"
    >
    > I am doing like this and the address is ok. does any one
    > know what is wrong here?[/color]
    [snip]

    You can't do it like this... Socket is a connection to the process not to
    the file. Once you establish your connection you need to use the protocol
    the server is using - http, most likely, in this case.


    Comment

    Working...