Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.net.SocketException : Connection Reset

 
Chaitanya Reddy
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
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
 
Cindy Glass
"The Hood"
Sheriff
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic