Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] Java web server proxy problem

This topic is 5372 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys: I just wrote a simple web server proxy, it using socket port 8080 , and I set my web browser''s LAN proxy using my IP address and socket port according my code. my proxy accept the browser(client)''s URL request, then get this request to the real server. get the web page content back to the client as a respond message.. every things fine except the image display.. I wonder why cause this problem.. does anybody can tell me this reason? this is my server proxy code.. import java.io.*; import java.util.*; import java.net.*; class RealServerProxy { public static void main(String argv[]) throws Exception { String requestMessageLine,inputLine,temp=""; String URLstring; ServerSocket listenSocket=new ServerSocket(8080); Socket connectionSocket=listenSocket.accept(); //accept the client''s web request BufferedReader inFromClient=new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient=new DataOutputStream(connectionSocket.getOutputStream()); requestMessageLine=inFromClient.readLine(); StringTokenizer tokenizedLine=new StringTokenizer(requestMessageLine); if(tokenizedLine.nextToken().equals("GET")) { //get URL from the request message of client URLstring=tokenizedLine.nextToken(); System.out.println(URLstring); URL myURL = new URL(URLstring); BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream())); //get all web page content. while ((inputLine = in.readLine()) != null) temp+=inputLine; System.out.println(temp); //send all string to the client. outToClient.writeBytes(temp); in.close(); connectionSocket.close(); } else System.out.println("Bad Request Message"); } }

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Images aren''t text. Don''t treat them like text, and the problem will disappear.

I suppose I could explain a BIT further... Quit using Readers and Writers. Use InputStreams and OutputSteams.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!