Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

basic socket program in Java

Thread view: 
Navodit - 04 Oct 2006 22:33 GMT
Hi

I am writing a simple socket program in java as follows:

    try {
           System.out.println("Creating a new socket...\n");
           echoSocket = new Socket("130.126.243.188", 1029);
           System.out.println("Socket created!\n");
           out = new PrintWriter(echoSocket.getOutputStream(), true);
           in = new BufferedReader(new InputStreamReader(
                                       echoSocket.getInputStream()));
       } catch (UnknownHostException e) {
           System.err.println("Don't know about host: 130.126.243.188.");
           System.exit(1);
       } catch (IOException e) {
           System.err.println("Couldn't get I/O for "
                              + "the connection to: 130.126.243.188.");
           System.exit(1);
       }

The ip address specified above is one of the machines on my network. I am
able to ping to this machine. However when i execute this program, I get the
error:
"Couldn't get I/O for the connection to: 130.126.243.188"

Can anyone point out the error to me here ? Thanks.
Andrew Thompson - 04 Oct 2006 23:25 GMT
> Can anyone point out the error to me here ?

Java can.

>         } catch (IOException e) {
>             System.err.println("Couldn't get I/O for "
>                                + "the connection to: 130.126.243.188.");

  // what went wrong?
  e.printStackTrace();

>             System.exit(1);
>         }

Andrew T.
Navodit - 05 Oct 2006 03:32 GMT
Thanks ! That resolved the error ... I was mixing up the IP addresses...

>> Can anyone point out the error to me here ?
>
[quoted text clipped - 11 lines]
>
> Andrew T.
Andrew Thompson - 05 Oct 2006 04:11 GMT
> Thanks !

Your future lack of top-posting, will be thanks enough.

(further comments below)

> "Andrew Thompson" <andrewthommo@gmail.com> wrote in message
> >
> >> Can anyone point out the error to me here ?
...
> >>         } catch (IOException e) {
...
> >   // what went wrong?
> >   e.printStackTrace();

>That resolved the error ...

Excellent!  Glad you sorted it.

Those stacktraces are invaluable, aren't they?

Generally, the only time I will suppress a stacktrace
printout is when I absolutely do not care that a problem
happened..
- a thread 'sleep' is interrupted // wake and continue
- a method/class is missing but we have a
 fall-back // 'set always on top' not available, use 'to front'
..even then, I will document why the exception is ignored.

>...I was mixing up the IP addresses...

..and thanks for reporting the solution.

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.