• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Connection using Sockets

 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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 ??
 
Tony Docherty
Bartender
Posts: 2989
59
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2989
59
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic