socket communication between browser-server-browser

hi,

I need to connect the browser to the internet via one proxy server.

My proxy server is working fine.

I am able to send request from browser to the proxy server and able to get back the response from the server.

But the problem is sending back the response from the server to the browser.

i tried using printstream to write in the browser but it is not working.

can anyone help me in this?

thanks a lot

[454 byte] By [parvathya] at [2007-10-3 2:54:23]
# 1

> I need to connect the browser to the internet via

> one proxy server.

> My proxy server is working fine.

Good.

> I am able to send request from browser to the proxy

> server and able to get back the response from the

> server.

So in other words you can send (browser->proxy->server) and receive (server->proxy->browser).

> But the problem is sending back the response from the

> server to the browser.

But you just said server->proxy->browser works.

> i tried using printstream to write in the browser but

> it is not working.

Now you seem to be talking about browser->proxy->server again, and you said that works too.

> can anyone help me in this?

Can anybody even understand it? Or what you mean by 'browser-server-browser'?

ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 2

hi

If a user type www.google.com in the browser,i am able to get the request from the browser and send it to the proxy server.and also able to get back the response from the proxy server.

I am having pbm in sending the response back to the browser to display the requested google page.

parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 3

> hi

> If a user type www.google.com in the browser,i am

> able to get the request from the browser and send it

> to the proxy server.and also able to get back the

> response from the proxy server.

So the proxy server can send to the browser.

> am having pbm in sending the response back to the

> browser to display the requested google page.

So the proxy server can't send to the browser.

I do not understand. You need to clarify your problem and maybe your thoughts as well.

ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 4

hi

I am sending the request to the proxy server using dataoutputstream

out.writeByte();

and tried to get the response from the proxy server using datainputstream

in.readByte().

After that i tried to store it in a file,only few datas like http1.1,302 found are getting stored in the file and some characares like

this is getting stored.

if i tried to sent this atleast to browser it is not working.

i tried to sent this data to browser using printstream ps.println()

thanks a lot

parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 5
I still can't make head or tail of what works and what doesn't work in this scenario.Long experience in this business tells me that being able to express the problem clearly is 60% of the way towards the solution.You really need to try harder than this.
ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 6

hi

Hope i am clear in my question now.

it is browser<->myapplication<-->proxyserver concept

not browser<->server<-->browser concept

I need to connect the browser to the internet via one proxy server.

My proxy server is working fine.

I am sending the request to the proxy server using dataoutputstream

out.writeByte();

and tried to get the response from the proxy server using datainputstream

in.readByte().

This two process are working fine.

After that i tried to store the response from the server in a file.

I tried to sent the response back to the server by reading from the file using

printstream ps.println().but it it not working.

Can anyone tell me how to sent back the response from the proxyserver to browser

Thanx a lot.

parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 7

> Hope i am clear in my question now.

Actually no.

> it is browser<->myapplication<-->proxyserver

> concept

> not browser<->server<-->browser concept

Good, this is new information. Incomprehensible but new.

The rest of it you have already said and it is still as incomprehensible as it always was.

Can you answer some or all of these questions:

WHY do you have this architecture? WHAT are you trying to accomplish? WHAT does a sample communication look like? WHERE is the problem located - in 'my application'? WHAT does the code there look like? WHAT have you tried? and WHAT does the incorrect output look like? and/or WHAT exception or behaviour are you seeing instead of what you expect?

As I said above, asking yourself the right questions is 60% of the way to a solution.

ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 8

WHY do you have this architecture?

WHAT are you trying to accomplish?

Im trying to connect to the internet via the proxy which ll do compression and speedup the internet acces.

WHERE is the problem located in 'my application'?

the pbm is in my application.

WHAT does the code there look like?

WHAT have you tried?

I did the following

1.Create a serversocket and the accept the browser request.

2.Store the request in a file.

3.send that request to the proxy server using another one client sokcet listening the proxyserver

4.Getting the response from the proxy server and storing it in a file again.

5.Reading from the file and tried to send it to the browser.

WHAT does the incorrect output look like?

Expected output is

if u type www.google.com,then google homepage

obtained output is

nothing get displayed in the browser.

parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 9
Thanks. Two questions.(a) is the file containing the data you receive from the proxy correct? and> WHAT does the code there look like?
ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 10

hi

The datas received from the proxy server is correct only.

The following is the code i used to send the data back to the browser

public void GetResponse()

{

try

{

FileOutputStream fos1 = new FileOutputStream("res.txt");

while((ch1 = in.readByte()) != -1)

{

//System.out.print((char)ch1);

fos1.write(ch1);

}//endofwhile*/

sendResponse();

}catch(Exception ert1){System.out.println("hi"+ert1.toString());}

}

public void sendResponse()throws Exception

{

FileInputStream fin1 = new FileInputStream("res.txt");

int c1 =0;

while((c1=fin1.read())!= -1)

{

nos.writeByte(c1);

//System.out.print((char)c1);

}

}

parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 11

OK, what is 'nos' that you're writing to and how is it obtained from the Socket? and is there a BufferedOutputStream in there somewhere? If so it needs flushing at the end of the file. Also, are you ever getting to the block where you write the file to 'nos' at all? It's not very likely that the proxy will close the socket on you, in which case the read() from the proxy will never return -1. I suggest that while you're writing the file you should write to 'nos' at the same time, not in a subsequent phase.

ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 12
hithanks for ur reply.I didnt get ur point that"while you're writing the file you should write to 'nos' at the same time, not in a subsequent phase."nos is dataoutputstream of browser.can u give me ur mailidthanks a lot for ur reply
parvathya at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...
# 13
if you don't understand that, you won't understand anything else I could say.
ejpa at 2007-7-14 20:43:27 > top of Java-index,Archived Forums,Socket Programming...