Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-2008, 09:30 AM
Member
 
Join Date: Jun 2008
Posts: 2
Tareq85 is on a distinguished road
Redirect My Client httpRequests to Proxy server !
Hello all ,
i have this set up :

internet
|
Router(Suse) ---- Content-Filter Server
|
LAN

am using iptables ( on the Router " Suse " ) to redirect client httprequests from Port 80 to my program's port (1500) that i developed on the router now in my code i want to send ( redirect ) all client http requests to the Content-filter server's port ( Squid-Server at 3128) and here is the code please ,

Code:
import java.io.*; import java.net.*; public class Test { public static void main(String[] args) { try { ServerSocket serverSocket = new ServerSocket(1406); while(true){ System.out.println("Waiting for request"); Socket socket = serverSocket.accept(); new Thread(new SimpleHttpHandler(socket)).run(); socket.close(); } } catch (Exception e) { e.printStackTrace(); } } } class SimpleHttpHandler implements Runnable{ private final static String CLRF = "\r\n"; private Socket client; private DataOutputStream writer; private BufferedReader reader; public SimpleHttpHandler(Socket client){ this.client = client; } public void run(){ try{ this.reader = new BufferedReader( new InputStreamReader( this.client.getInputStream() ) ); InetAddress ipp=InetAddress.getByName("192.168.6.29"); //192.168.6.29 ip of the proxy server System.out.println(ipp); StringBuffer buffer = new StringBuffer(); Socket ss=new Socket(ipp,3128); this.writer= new DataOutputStream(ss.getOutputStream()); writer.writeBytes(this.read()); this.writer.close(); this.reader.close(); this.client.close(); } catch(Exception e){ e.printStackTrace(); } } private String read() throws IOException{ String in = ""; StringBuffer buffer = new StringBuffer(); while(!(in = this.reader.readLine()).trim().equals("")){ buffer.append(in + "\n"); } System.out.println(buffer.toString()); return buffer.toString(); } }
my probelm is as follows :

1) i can read the httpRequest from the client and i could output it and it's correct

2)am not sure about the way that am using to send the httpRequest to Squid-Server, becuase my clients don't get response ( am i reading correctly the whole httpRequest ? is this the correct way to redirect the httpRequest to the Proxy-Server ?

Best regards,
Tareq
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading URL using java through proxy server asheesh Networking 15 08-24-2008 04:45 PM
Redirect My Client httpRequests . Tareq85 Advanced Java 0 06-09-2008 04:40 PM
how client know what kind of server lemur Networking 3 05-31-2008 08:11 AM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 10:18 AM
Problems with client and server Albert Advanced Java 2 07-02-2007 07:07 AM


All times are GMT +3. The time now is 09:37 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org