Skip to main content
gamedev.net
🔒 Locked

[java] Java web server proxy problem

Started by xqwww Jan 24, 2004 at 1:41 AM 1 replies 500+ views
Original Post
xqwww
xqwww
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"); } }
Game is my Dream
xqwww
xqwww
yes.. I should use data input output instead..
Game is my Dream

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.