Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to display image at client site??

How to display image at client site??

Scheduled Pinned Locked Moved C#
htmlsysadmindata-structureshelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bluebamboo
    wrote on last edited by
    #1

    Hi all, i made a simple proxyserver which can display basic HTML page at client site, but i have no idea why the image part of webpage always gone!! following is my simple code which accept the request from client site, then reponse. int port = 8080; // Create server socket Socket proxyServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp); proxyServer.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 5000); // call the Listen method to listen for and queue incoming connection requests. proxyServer.Bind( new IPEndPoint(GetHostIP(), port) ); proxyServer.Listen( port ); // Display start message Console.WriteLine("ProxyServer started at port " + port); Console.WriteLine("ProxyServer ready for accepting incoming connections..."); //endless loop while(true) { // waiting for client Socket clientConnect = proxyServer.Accept(); // Create the NetworkStream for communicating with the remote host. NetworkStream clientStream = new NetworkStream( clientConnect, true ); HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create("http://www.google.co.uk/intl/en_uk/images/logo.gif"); // Set properties - 10 secs loHttp.Timeout = 10000; // Retrieve request info headers HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse(); System.IO.StreamReader loResponseStream = new System.IO.StreamReader(loWebResponse.GetResponseStream() , System.Text.Encoding.UTF8); Byte[] buf = System.Text.Encoding.UTF8.GetBytes( loResponseStream.ReadToEnd() ); //Console.WriteLine(lcHtml); loWebResponse.Close(); loResponseStream.Close(); clientStream.Write(buf, 0, buf.Length); clientStream.Flush(); clientStream.Close(); } plz help me out~~ many thanks!

    L 1 Reply Last reply
    0
    • B Bluebamboo

      Hi all, i made a simple proxyserver which can display basic HTML page at client site, but i have no idea why the image part of webpage always gone!! following is my simple code which accept the request from client site, then reponse. int port = 8080; // Create server socket Socket proxyServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp); proxyServer.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 5000); // call the Listen method to listen for and queue incoming connection requests. proxyServer.Bind( new IPEndPoint(GetHostIP(), port) ); proxyServer.Listen( port ); // Display start message Console.WriteLine("ProxyServer started at port " + port); Console.WriteLine("ProxyServer ready for accepting incoming connections..."); //endless loop while(true) { // waiting for client Socket clientConnect = proxyServer.Accept(); // Create the NetworkStream for communicating with the remote host. NetworkStream clientStream = new NetworkStream( clientConnect, true ); HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create("http://www.google.co.uk/intl/en_uk/images/logo.gif"); // Set properties - 10 secs loHttp.Timeout = 10000; // Retrieve request info headers HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse(); System.IO.StreamReader loResponseStream = new System.IO.StreamReader(loWebResponse.GetResponseStream() , System.Text.Encoding.UTF8); Byte[] buf = System.Text.Encoding.UTF8.GetBytes( loResponseStream.ReadToEnd() ); //Console.WriteLine(lcHtml); loWebResponse.Close(); loResponseStream.Close(); clientStream.Write(buf, 0, buf.Length); clientStream.Flush(); clientStream.Close(); } plz help me out~~ many thanks!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Bluebamboo wrote:

      plz help me out

      Isolate the code that downloads the GIF file and unit test it.

      B 1 Reply Last reply
      0
      • L led mike

        Bluebamboo wrote:

        plz help me out

        Isolate the code that downloads the GIF file and unit test it.

        B Offline
        B Offline
        Bluebamboo
        wrote on last edited by
        #3

        Hi mike, Thanks for your reply,but i am not quite clear about what you said, do you mean i should save my code part in GIF format file then upload it? GIF? a picture?:confused:

        L 1 Reply Last reply
        0
        • B Bluebamboo

          Hi mike, Thanks for your reply,but i am not quite clear about what you said, do you mean i should save my code part in GIF format file then upload it? GIF? a picture?:confused:

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          The part that uses a HttpWebRequest to download the image file resulting in a byte array containing the image. That should be isolated and unit tested. The unit test could save the byte array to a disk file that can be verified to be correct. None of that has anything to do with your "proxyServer" and sending the byte array to the client socket. That is why it can and should be "isolated". Take some time to read about software design principles.

          "Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?"
          Colin Angus Mackay in the C# forum

          led mike

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups