开发者

Java - trouble running basic socket networking program

开发者 https://www.devze.com 2023-03-27 14:52 出处:网络
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.

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


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


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.)


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)


try this: change taranishost name to localhost

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号