Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

java.net.SocketException : Connection Reset

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I am trying to connect to URL through the following code.
u=new URL("http://www.rcsb.org/pdb/cgi/explore.cgi?job=download;pdbId=1KIT;page=;pid=8231059904141&opt=show&format=PDB&pre=1");
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", "192.168.36.204");
System.getProperties().put("proxyPort", "80");
u.setDoOutput(true);
u.setUseCaches(true);
theHTML = new DataInputStream(u.openStream());
while ((thisLine = theHTML.readLine()) != null)
{
if(thisLine.startsWith("HELIX"))
{
sb=thisLine;
System.out.println(thisLine);
while ((thisLine = theHTML.readLine())!=null)
{
System.out.println(thisLine);
if(thisLine.startsWith("MASTER"))
{
break;
}
else
{
sb=sb+"\n"+thisLine;
}
}
}
}
It successfully gets connected to the specified URL.But after printing a few lines on to the screen,the program stops by invoking "java.net.SocketException" .How to handle this exception?

And also is there any more efficient mechanism to connect to URLs other than the above one.If so, please write to me.
Please reply me as soon as possible.
Regards,
Chaitanya Reddy
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would certainly use a BufferedInputStream rather than DataInputStream.
Surely that is not the real code, I dont see setDoOutput in java.net.URL - is that a URLConnection.
Bill
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chaitanya,
Welcome to JavaRanch!! Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each.
We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy
[ August 05, 2003: Message edited by: Cindy Glass ]
 
Chaitanya Reddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello William Brogden ,
Thanks for your reply.Yeah u r right Mr.Brogden.I missed out few statements while I was copying from my program.
I will try out your method.
Thanks anyway.
Chaitu
 
Slime does not pay. Always keep your tiny ad dry.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic