File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket programming help

 
vemuri kishore
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a piece of code ,this code is working in a different program individually but it does not work in the proxy server. It extracts the response from the website and when i write it to a something like out.html it writes the whole page but it does not write back to the socket for the web browser.


guys if any one of you has a idea why this happens ,please do reply.


if(request.startsWith("CONNECT"))
{
url = request.substring(8,c-13);
String raw_request=null;
//raw_request = sslhandler(url);

/******************* Creating and handling https requests ******************/
// Socket socket = SSLSocketFactory.getDefault().createSocket(url, 443);
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket)factory.createSocket(url, 443);
sslsocket.startHandshake();
//try
// {
//Writer sout = new OutputStreamWriter(socket.getOutputStream());
PrintWriter sout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sslsocket.getOutputStream())));
sout.println("GET / HTTP/1.0");
//sout.
sout.println();
sout.flush();
if (sout.checkError())
System.out.println("SSLSocketClient: java.io.PrintWriter error");

//OutputStream socket_out = socket.getOutputStream();
//request = request + "\r\n";
//socket_out.write(request.getBytes());*/
InputStream sin = sslsocket.getInputStream();
BufferedReader in1 = new BufferedReader(new InputStreamReader(sin));
raw_request = getRawRequest1(sin);
System.out.println(raw_request+"\r\n");

/*************Transferring requested Web Page to Web Browser************/
//out.write(raw_request.getBytes());
String inputLine;
PrintWriter out1 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
while ((inputLine = in1.readLine()) != null)
out1.println(inputLine);
//out.write(socket_in.read());
Logobj.logEntry("Transferred "+raw_request.length()+" bytes of data to browser of "+socket.getInetAddress() + ":" +socket.getPort());
ppt.doit("Transferred "+raw_request.length()+" bytes of data to browser of "+socket.getInetAddress() +":"+socket.getPort(),jta);
out1.flush();
sout.close();
sin.close();
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic