UnknownHostException



I wanna access simple Http site...

I think ter is an error in the socket obj creation... pls help
urgent...

import java.io.*;
import java.net.*;
public class http
{
public static void main(String[] args)
{
try
{
OutputStream to_file = new FileOutputStream("f:
temp.txt");
URL url = new URL("http://www.wickedlysmart.com/HeadFirst/
HeadFirstJava/HeadFirstJavaIndex.html");
String protocol = url.getProtocol();
String host = url.getHost();
int port = url.getPort();
if(port == -1) port = 80;
String filename =url.getFile();
System.out.println(filename+"\n\n");
Socket socket = new Socket(host, port);
InputStream from_server = socket.getInputStream();
PrintWriter to_server = new PrintWriter(socket.getOutputStream());
to_server.print("Get" + filename +"\n\n");
to_server.flush();
byte[] buffer = new byte[4096];
int byte_read;
while((byte_read = from_server.read(buffer)) != -1)
{
to_file.write(buffer,0,byte_read);
System.out.print((char)byte_read);
}
socket.close();
to_file.close();

}
catch(Exception e)
{
e.printStackTrace();
}

}
}

Output:

C:\java\bin>java Http

/HeadFirst/HeadFirstJava/HeadFirstJavaIndex.html

java.net.UnknownHostException: www.wickedlysmart.com
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:178)
at Http.main(Http.java:20)

C:\java\bin>

the output file f:\temp.txt is created but empty...:(
pls help out from this error...

.



Relevant Pages

  • GNAT.Sockets writing data to nowhere...
    ... I can connect to localhost:25 and conduct an SMTP session using ... Server_User: in String; ... -- Write Data to Socket. ... 22630 smtp_client RET setsockopt 0 ...
    (comp.lang.ada)
  • Re: Parallel processing questions
    ... instead of from ActiveX exe. ... Did you mean that while the server socket is sending ... > RealHostName As String ... >Private Type SMTPRemoteServer ...
    (microsoft.public.vb.general.discussion)
  • Winsock Control and Responding to Error Situations
    ... I have an application that impliments the winsock control in a control array ... So when I close the socket I call a function CloseSocket. ... Public Sub CloseSocket ... Dim strTag As String ...
    (microsoft.public.vb.controls.internet)
  • Re: Issue with multiple threads and System.Net.Sockets.Socket
    ... first off your app has a 200 loop count, I am pritty sure you can only throw ... private thd as system.threading.thread ... private eip as string ... Are you closing the socket out? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Master/worker design
    ... > 1) I am trying to multiplex text and binary data on the same socket. ... will tell you the number of elements in any string. ... before you can measure and transmit it. ...
    (comp.lang.tcl)