| Author |
Trouble with Head First "Advice Guy" and Sockets
|
Phil Hopgood
Ranch Hand
Joined: Jul 14, 2008
Posts: 47
|
|
Hi all, I'm having trouble with the "DailyAdviceClient" example in Head First chapter 15. I've typed in the example as shown below: When I run this I get the following exception:
java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Metho at java.net.PlainSocketImpl.doConnect(PlainSocketImpl. at java.net.PlainSocketImpl.connectToAddress(PlainSock at java.net.PlainSocketImpl.connect(PlainSocketImpl.ja at java.net.SocksSocketImpl.connect(SocksSocketImpl.ja at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at java.net.Socket.<init>(Socket.java:366) at java.net.Socket.<init>(Socket.java:180) at DailyAdviceClient.go(DailyAdviceClient.java:9) at DailyAdviceClient.main(DailyAdviceClient.java:26)
Obviously my socket connection has been refused. Why is this? Have I coded this incorrectly? Is this server no longer valid? - after all the book was written a few years back. I've had a quick Google and a search on JavaRanch and found no relevant references. I'd appreciate any inputs. Regards and thanks. Phil
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
The above code for the client program seems to have no problem. Do you have a server program running before you execute the client? And is the server listening on the same port where the client is connecting to? Hope this helps  [ August 22, 2008: Message edited by: Amit Ghorpade ]
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Phil Hopgood
Ranch Hand
Joined: Jul 14, 2008
Posts: 47
|
|
Amit, That's a very good point! I had just typed in the code from the book assuming it was connecting to some server or other. Of course "127.0.0.1" is local host, so no I don't have any server program running! What a twit I am. In the preceding text of the book they use "190.165.1.103" so I tried that and it just times out. So either this was just an example that they didn't expect anyone to run, i.e. this "Advice Guy" service doesn't exist or it now no longer exists. Thanks for your help. Regards, Phil.
|
 |
Phil Hopgood
Ranch Hand
Joined: Jul 14, 2008
Posts: 47
|
|
Oh no!! I have just read a bit further through the book and they've gone through the server code that's needed to make this work a few pages later! How embarrassing. I guess I was too keen to get it coded and should have read the next few pages before getting going, what a larf ...... Regards, Phil.
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
I knew you would figure it out yourself . Good work Phil Cheers
|
 |
 |
|
|
subject: Trouble with Head First "Advice Guy" and Sockets
|
|
|