This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes Socket communication external web server (Apache) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket communication external web server (Apache)" Watch "Socket communication external web server (Apache)" New topic
Author

Socket communication external web server (Apache)

Rácz György
Greenhorn

Joined: Nov 12, 2008
Posts: 19
Hi!

Sorry for my bad english! I have got a big problem... I develop struts web application java 6 with apache tomcat. This web application one most important function is read RSS sites. One RSS site (www.ft.com/rss/world) redirected (statusCode = 302), so I connect this site with Socket and send GET /rss/world HTTP/1.0 User-Agent: Wget/1.9.1 message, respose I give RSS site in XML format. This is work fine in sample java programme, but not in web application.
Simple java program source code:


And here is my web application class code:


When the program execute on while ((str = rd.readLine()) != null) { then nothing happend...no exception but my web app not response!

Please help me!
Rácz György
Greenhorn

Joined: Nov 12, 2008
Posts: 19
Hi Coders!

I set up socket.setSoTimeout(2000); then I receive java.net.SocketTimeoutException: Read timed out. The socket connected: true and socket closed: false.

How can I read the socket correctly?
How can I handle SocketTimeoutException?

Please help me!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill
Rácz György
Greenhorn

Joined: Nov 12, 2008
Posts: 19
William Brogden wrote:Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill


Hi Bill!

Here is some line from my NewsAction source code. If statusCode = 301 vagy 302 (site redirect) then I need read RSS xml file with Socket.

How I read redirected site with HttpURLConnection?



Thank you! Please post example source code...

Best regards!
Rácz György
Greenhorn

Joined: Nov 12, 2008
Posts: 19
R�cz Gy�rgy wrote:
William Brogden wrote:Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill


Hi Bill!

Here is some line from my NewsAction source code. If statusCode = 301 vagy 302 (site redirect) then I need read RSS xml file with Socket.

How I read redirected site with HttpURLConnection?



Thank you! Please post example source code...

Best regards!



Hi Coders!

I found what is the problem...I copy my source code and create a new thick (not a web app) java program, this java code work fine, I received the RSS XML file. Then I comment the following lines in my new thick java application, and I received same IOException: java.net.SocketTimeoutException: Read timed out exception as my web application. So in Apache webapp I can't write my request to the Socket. I dont know why! Can anybody help me? Why I cannot write to the output socket OutputStream?

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

(sorry to disturb, but you can fix your display name in My Profile)


[My Blog]
All roads lead to JavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Socket communication external web server (Apache)