Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Client Socket - Getting Basic Error

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
0
0
US
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.
 
Hey there,

I am running java 1.4.1 on redhat 7.1. I compiled and ran your code first try with no problems.

Maybe try to run it again at another time during the day???
 
Hi scoon,

That's what the Webmaster suggested. I waited again until this morning, and I'm getting the same thing, "Connection timed out", so I'll just keep trying.

I got another tutorial to work, though, so at least I have seen socket programming operate.

Thanks for your help,
scripter73
Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top