Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

Transfer received image

Thread view: 
pvsnmp@yahoo.com - 08 Sep 2005 20:58 GMT
Hi,
I am trying to write a code for a server which will do the
functionality of web proxy.
 Client------Proxy--------Server
The proxy will function as entry point to a cluster of servers, in
simple terms like an application level gateway.
I am able to fetch html text content from server and send to the client
but unable to do the same for images. Can anyone give some input on how
to do this?
I am a beginner in Java.

thanks and rgds,
Prashant
Oliver Wong - 08 Sep 2005 21:09 GMT
> Hi,
> I am trying to write a code for a server which will do the
[quoted text clipped - 6 lines]
> to do this?
> I am a beginner in Java.

   What happens when you do what you did for HTML and apply it to images?
Runtime exceptions? Compilation errors? Unexpected behaviour? Your problem
description is too vague.

   - Oliver
pvsnmp@yahoo.com - 08 Sep 2005 21:19 GMT
Hi,
I use BufferedReader to read the HTTP message sent to the proxy from
the server. So I use the readLine() method and then write every line to
the outputstream of the socket connecting the client.
When I try it request images , the browser displays the message that
the image cannot be displayed as it contains errors.
I understand that its because it has not been sent to the browser in
the right format . But how can i do that?

thanks and regards,
Prashant
Oliver Wong - 08 Sep 2005 21:56 GMT
> Hi,
> I use BufferedReader to read the HTTP message sent to the proxy from
[quoted text clipped - 4 lines]
> I understand that its because it has not been sent to the browser in
> the right format . But how can i do that?

   I'm assuming you use writeLine(), println() or something equivalent (you
should have specified what you're using to write). These methods do line
ending conversion. That is, if your proxy receives "\r" because, it might
write out "\n\r", thus changing the content of the data.

   Instead, you should read the data into an array of bytes so that no
line-ending conversion occurs. See the read(char[], int, int) method in
BufferedReader, and its equivalent in whatever you're using to write.

   - Oliver
pvsnmp@yahoo.com - 08 Sep 2005 22:30 GMT
Hi,
thanks for the info , I am using println( )
I will try the way you suggested, but how do i set the size of the
character array?
Also, I have been reading that data such as images must be read using
byte streams and not character streams. And if i have to use bytestream
how big should be the byte array that has to be created?

thanks and rgds,
Prashant
Oliver Wong - 08 Sep 2005 22:32 GMT
> Hi,
> thanks for the info , I am using println( )
> I will try the way you suggested, but how do i set the size of the
> character array?

char[] myCharacterArray = new char[THE_DESIRED_SIZE];

> Also, I have been reading that data such as images must be read using
> byte streams and not character streams. And if i have to use bytestream
> how big should be the byte array that has to be created?

   I don't know of any good rule for this. I think 256 and 1024 are popular
sizes.

   - Oliver
pvsnmp@yahoo.com - 08 Sep 2005 23:04 GMT
Hi,
>char[] myCharacterArray = new char[THE_DESIRED_SIZE];
I know this , but i am wondering about what should be the value of
THE_DESIRED_SIZE  ?
Anyway thanks,
I found a posting of a problem which I think I am encountering as well
titled 'Using Reader and Stream classes on same Input'

http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/ab
a23d1bdf28b48d/9ad85c870e71d08c?q=BufferedInputStream&rnum=88#9ad85c870e71d08c


rgds,
Prashant
Roedy Green - 08 Sep 2005 23:45 GMT
>I use BufferedReader to read the HTTP message sent to the proxy from
>the server. So I use the readLine() method and then write every line to
[quoted text clipped - 3 lines]
>I understand that its because it has not been sent to the browser in
>the right format . But how can i do that?

Images are binary. They are not lines of text.  See
http://mindprod.com/applets/fileio.html
for how to read binary as opposed to character data.

Think of an image as an octet-stream, 8-bit bytes read raw with no
translation of any kind.  BufferedReaders convert 8-bit streams to
16-bit characters. They are designed for human-readable data.

See http://mindprod.com/jgloss/urlconnection.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 08 Sep 2005 23:42 GMT
>I am able to fetch html text content from server and send to the client
>but unable to do the same for images. Can anyone give some input on how
>to do this?

This is a bit advanced to entrust to a newbie.  

You need some understanding of HTTP protocol.  I suggest starting at
http://mindprod.com/jgloss/cgi.html
and getting a copy of Core Web Programming.

Also get packet sniffer. See
http://mindprod.com/jgloss/packetsniffer.html

and watch a browser talking to a server to get web pages, images etc.
You have to stand in the middle and look like a browser to the cluster
servers and like server to the browser.

There are other ways of tackling this, e.g. rotating DNS over an IP
farm that distributes the load over your servers where clients talk
directly to servers.   See http://mindprod.com/jgloss/dns.html

You can farm the incoming requests to servers and have them talk
directly back to the end users, rather than you acting as proxy
man-in-the-middle and potential bottleneck.

Unless you are doing something quite fancy, chances are you can find
and off the shelf solution.

These things are pretty simple in principle, but rapidly get
complicated when you start trying to make them handle heavy traffic.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

pvsnmp@yahoo.com - 08 Sep 2005 23:49 GMT
Hi,
Thanks for the reply.
I am already using ethereal and sniffing the packets and trying to
understand whats happening ,
yes its complicated for a newbie, but i didnt expect it initially when
i saw that the html pages were working fine.
And I am not using rotating DNS , and yes I am trying to do something
fancy :-). Yes I agree with you that during heavy traffic , such things
might result in poor performance.

thanks and rgds,
Prashant


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.