This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes How to run Client socket? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to run Client socket?" Watch "How to run Client socket?" New topic

How to run Client socket?

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
HI, all
the following code has no problem in complilation,But when I try to run it, It gives me the error even if I change host
I guese there is some port problmes?
thanks in advance
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("", 7000);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(;
String userInput;
while ((userInput = stdIn.readLine()) != null) {
System.out.println("echo: " + in.readLine());

C:\java\NETWORK>java EchoClient
Couldn't get I/O for the connection to: taranis.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
HI, all
ignore the previous question ! I got it
Sorry I forget to run the serversock first
I agree. Here's the link:
subject: How to run Client socket?
It's not a secret anymore!