0

I have tried the example provided by Oracle, but when I run the program (through the Windows 7 CMD), I get the following error: "Don't know about host" + hostName

The code looks like this (exactly the same as the one provided by Oracle):

KnockKnockClient http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java

KnockKnockServer http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java

The KnockKnockProtocol does not really matter, but it is also on there.

I do not know why I get to the exception every time...

And I run the program according to the same links as above.

Regards

user2990057
  • 121
  • 2
  • 10
  • Are you running the two processes on the same host (i.e. using `hostName` localhost)? – andersschuller Jan 20 '14 at 19:23
  • how are you running the applications? which parameters? – gipsh Jan 20 '14 at 19:24
  • Yes, if by host, you mean from the same computer. I have two different cmd windows from which, I start the client in one, and the server in the other. I run the program like this: java KnockKnockServer 4444 java KnockKnockClient test.example.com 4444 – user2990057 Jan 20 '14 at 20:02
  • This is a textbook example of why you shouldn't make up your own error messages. The sample is gravely at fault here. It is possible in this case to guess that the original exception was UnknownHostException, but it shouldn't be necessary to guess at all. – user207421 Jan 20 '14 at 23:08

1 Answers1

0

Of course, you're running the application without any parameters given.

Parameters the program expects:
Server:

Usage: java KnockKnockServer <port number>

Client:

Usage: java EchoClient <host name> <port number>

Example for parameters possible:
Server:
Running from CommandLine:

java KnockKnockServer 55555

Running from IDE:

55555

Client:
Running from CommandLine:

java EchoClient localhost 55555

Running from IDE:

localhost 55555

Edit, also solution for beginner.

Change:

Change String hostName = args[0];
int portNumber = Integer.parseInt(args[1]);

To:

String hostName = "localhost";
int portNumber = 55555;

At client class you will just need to change portNumber because it's the only showing (in purpose).

Orel Eraki
  • 11,940
  • 3
  • 28
  • 36
  • No, I am not. I do write both the portnumber and the hostname on the client side, and the portnumber on the server side... – user2990057 Jan 20 '14 at 20:00
  • @user2990057, Which IDE you're using ? Eclipse.. IntelliJ.. NetBeans ? – Orel Eraki Jan 20 '14 at 20:01
  • I use Eclipse, but I run the program from the terminal window that Windows 7 offers. I don't even know how to run it from Eclipse... – user2990057 Jan 20 '14 at 20:16
  • @user2990057, Please read JonSkeet answer here: http://stackoverflow.com/questions/12222153/eclipse-how-we-take-arguments-for-main-when-run And follow the link he gave with instructions. – Orel Eraki Jan 20 '14 at 20:37
  • I have done that, still does not work... I understand everything, except that thing with prompting the user to write a command... – user2990057 Jan 20 '14 at 21:06
  • @user2990057, You know what.. :), there is a better solution. Look in a minute at my answer. – Orel Eraki Jan 20 '14 at 21:21
  • Okay, the hard coded solution worked, thanks for that. Any reason why the other solution did not work? I did recieve some kind of warning from Windows Security which I did not pay that much attention to, could it be that? – user2990057 Jan 20 '14 at 22:16