• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Error in Connection using 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
Well guys, i'm totally new to Java..
I made the following stuff.. it runs, but no action is performed when i try to send it.
The cod is,



The errors i got are..
run:

I don't understand any part of error here..What exactly are these errrors, and how to re-solve 'em ??
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first exception is thrown because the socket was unable to connect to anything. Presumably you don't have anything listening for a connection on port 4000 on the localhost.
The other exceptions were thrown because your code ignores the fact that there is no connection and carries on as if there was one. Unfortunately the reader and writer objects haven't been created because of the first exception, hence the NPE's.
 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:The first exception is thrown because the socket was unable to connect to anything. Presumably you don't have anything listening for a connection on port 4000 on the localhost.


What does that means?
How can i make something listen to that port ??
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to create a ServerSocket to accept the connection, receive whatever the socket sends and then send something back.

I suggest you read http://docs.oracle.com/javase/tutorial/networking/sockets/index.html
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic