Socket Exception
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   devi_ramasubbu
Posted On:   Friday, June 8, 2001 06:18 AM

hello everybody i got socket exception while trying the following program.is it due to the port no plm? could u pls give me the possible soln? import java.net.*; import java.io.*; class whois{ public static void main(String ar[]) throws SocketException { try { int c; Socket s=new Socket("internic.net",80); InputStream in=s.getInputStream(); OutputStream out=s.getOutputStream(); String str=(ar.length==0 ? "starwave-dom":ar[0])+" "; byte buf[]=str.getBytes(); out.write(buf); while((c=in.read())!=-1) { System.out.print((char)c); } s.close(); }catch   More>>

hello everybody
i got socket exception while trying the following program.is it due to the port no plm? could u pls give me the possible soln?

			
import java.net.*;
import java.io.*;
class whois{
public static void main(String ar[]) throws SocketException
{
try
{
int c;
Socket s=new Socket("internic.net",80);
InputStream in=s.getInputStream();
OutputStream out=s.getOutputStream();
String str=(ar.length==0 ? "starwave-dom":ar[0])+"
";
byte buf[]=str.getBytes();
out.write(buf);
while((c=in.read())!=-1)
{
System.out.print((char)c);
}
s.close();

}catch(Exception e){
System.out.println(e);}
}

}

thank u    <<Less

Re: Socket Exception

Posted By:   Tim_Rohaly  
Posted On:   Friday, June 8, 2001 01:53 PM

What do you think you're trying to do? If you
open a socket to an HTTP server, you have to
speak HTTP protocol over that socket. Just sending
one string is not HTTP. If you want to
do this properly, you best first read the Networking FAQs
and read the HTTP specification at http://www.w3.org/Protocols/.
I also suggest you look in the FAQ for URLConnection
which may be a simpler way to do what you want.
About | Sitemap | Contact