scripter73
Programmer
I was working through a tutorial on Sockets. I'm just now learning about them. I copied this code from a site. It says I should receive the time, but I get an error. What's wrong? I think the connection timed out, but when I ping the address, I get a reply. Please help. I have tried to run several examples, and I haven't gotten anything back yet from any of them.
======
CODE
======
import java.io.*; // These two are needed for socket support
import java.net.*;
public class Client
{
public static void main(String args[])
{
try
{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line;
while(( line = in.readLine()) != null)
System.out.println(line);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
======
ERROR
======
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.docConnect(PlainSocket.Impl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.(init)(Socket.java:290)
at java.net.Socket.(init)(Socket.java:118)
at Client.main(Client.java:14)
Thanks for any help.
Change Your Thinking, Change Your Life.
======
CODE
======
import java.io.*; // These two are needed for socket support
import java.net.*;
public class Client
{
public static void main(String args[])
{
try
{
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line;
while(( line = in.readLine()) != null)
System.out.println(line);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
======
ERROR
======
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.docConnect(PlainSocket.Impl.java:295)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:161)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148)
at java.net.Socket.connect(Socket.java:425)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.(init)(Socket.java:290)
at java.net.Socket.(init)(Socket.java:118)
at Client.main(Client.java:14)
Thanks for any help.
Change Your Thinking, Change Your Life.