Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple socket question

0 views
Skip to first unread message

Eddy Ho

unread,
Dec 11, 1996, 3:00:00 AM12/11/96
to

Greetings. I'm new to Java so I'm trying out its network capability.
I wrote a very simple socket program in C that gets the time from a
server on port 13 (TCP), and it works. But when I tried to do the same
thing in Java, it just crashed. This is the code from Core Java that
I was testing on.

import java.io.*;
import java.net.*;

class SCTest
{
public static void main(String[] args)
{
try
{
Socket t = new Socket("199.2.139.2", 13);
DataInputStream is = new DataInputStream(t.getInputStream());
boolean more = true;
while(more)
{
String str = is.readLine();
if(str == null) more = false;
else System.out.println(str);
}
}
catch(IOException e)
{
{
System.out.println("Error " + e);
}
}
}

This is the error that returned from the Java pmg.

java.lang.NullPointerException
at java.net.InetAddress.getAllByName(InetAddress.java:250)
at java.net.InetAddress.getByName(InetAddress.java:209)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:87)
at java.net.Socket.<init>(Socket.java:87)
at java.net.Socket.<init>(Socket.java:62)
at SCTest.main(SCTest.java:10)

I've tried putting the IP address in dotted and string format but
neither works (the addr works in C).
What's wrong ? I'm running this pmg on a RS6000 PowerPC cluster running
on AIX ver 4.1. The compilier is an IBM Java compilier 1.0.2C (I think)
with the JIT compilier.

Thanks for any help. Please email me at edd...@cs.umt.edu if possible.
Bunch of thanks in advance.

Life is hard... and then you die.

unread,
Dec 13, 1996, 3:00:00 AM12/13/96
to

Eddy Ho wrote:
>
[snip]

> Socket t = new Socket("199.2.139.2", 13);
[snip]

> This is the error that returned from the Java pmg.
>
> java.lang.NullPointerException
> at java.net.InetAddress.getAllByName(InetAddress.java:250)
> at java.net.InetAddress.getByName(InetAddress.java:209)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:87)
> at java.net.Socket.<init>(Socket.java:87)
> at java.net.Socket.<init>(Socket.java:62)
> at SCTest.main(SCTest.java:10)
[snip]

I don't recal having gotten a NullPointerException, but try the fixed
InetAddress from http://www.cdt.luth.se/~peppar/java/InetAddress/ and
see if that doesn't solve your problem.


Cheers,

Ronald

0 new messages