• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Trouble with Head First "Advice Guy" and Sockets

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Phil Hopgood
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I knew you would figure it out yourself .
Good work Phil
Cheers
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic