1

I'm trying to implement Sun's example Socket program, i.e. the KnockKnock server and client found here: http://download.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

So I build the 3 files (EchoClient, KnockKnockServer, KnockKnockProtocol) into a project, build them, then go to cmd to run them:

> java KnockKnockServer
> Could not listen on port: 4444. 

Also, I have trouble with the EchoClient (not that it means much since the server doesn't work). I get the following:

> java EchoClient
> Couldn't get I/O for the connection to: localhost 

The one thing I changed in EchoClient class was to try and connect to "localhost" instead of their example machine "taranis". I don't understand the I/O error at all though.

So I need to figure this stuff out so I can later adapt it. Here's what I'm wondering: how do I know what port listen for in the KK Server? And if I want to connect to another computer in the EchoClient, would I directly put their (IPv4) IP address instead of "localhost"?

Thank you for any help

2
  • Maybe a program is already using port 4444. What does it say when you run lsof -i :4444 on the command line? Commented Aug 12, 2011 at 19:12
  • Uhh, I get "'lsof' is not recognized as an internal or external command, operable program or batch file." Commented Aug 12, 2011 at 19:21

4 Answers 4

4

Try a different (higher port) because 4444 might already be in use on your machine:

Technical description for port 4444:

The port 4444 is specifically assigned to the Kerberos 5 authentication features particularly the implementation of Kerberos 4 in various systems including those running under the Mac OS X platform. The communication port 4444 is used in the conversion of Kerberos 5 credentials into an acceptable Kerberos 4 format.

source

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for that. What are some other good ports I could try? I don't know too much about the different ports.
Try any number above 10000. Your MAX is 65535, is I think.
Alright so I tried 4601 (found it in the link in this answer) and now I don't get the error but the command line just hangs there. It appears that the program is frozen. What's up with that?
1

That tutorial breaks rule #2 about handling exceptions: it makes up its own error message ' Couldn't get I/O for the connection to: ...' instead of printing the actual exception. Change it to do that, then you have some hope of finding out what went wrong.

I complained about that tutorial about eight years ago ;-(

(Rule #1 is print something.)

Comments

0

I had this problem yesterday when I was trying to learn the same thing you are!

1) Make sure both the server and client have the same port for example:

kkSocket = new Socket("localhost", 802); //Client 

serverSocket = new ServerSocket(802); //Server (I ran into this problem by accident)

2) Try changing both the server's port and the clients' port to 10000 or higher

3)The program outputs "Knock! Knock!" and than you need to type the input.(The hang you described might just be the server waiting for an input)

Comments

0

try this: change taranishost name to localhost

kkSocket = new Socket("localhost", 4444);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.