Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA24113; Wed, 29 Nov 95 15:37:59 EST
Received: from liquor.cabi.net by MIT.EDU with SMTP
	id AA17219; Wed, 29 Nov 95 15:36:44 EST
Received: (from listadm@localhost) by liquor.cabi.net (8.6.12/8.6.12) id PAA27556; Wed, 29 Nov 1995 15:15:33 -0500
Resent-Date: Wed, 29 Nov 1995 15:15:33 -0500
Date: Wed, 29 Nov 1995 12:30:17 -0800
From: Thomas Boutell <boutell@boutell.com>
Message-Id: <199511292030.AA11624@boutell.com>
To: java-linux@substance.blackdown.org
Subject: sun.net.* classes broken in Linux port of JDK?
Resent-Message-Id: <"Df_Uc2.0.pj6.axBlm"@liquor>
Resent-From: java-linux@java.blackdown.org
X-Mailing-List: <java-linux@java.blackdown.org> archive/latest/584
X-Loop: java-linux@java.blackdown.org
Precedence: list
Resent-Sender: java-linux-request@java.blackdown.org



Are the sun.net.* classes broken in the Linux port of 
the JDK?

The following demo was sent to me by one of the
engineers at Sun. 

To test it, save this to the file "demo.java" and do
"javac demo.java". Then do "java DatagramServer &" and
"java DatagramClient localhost port#" where port# should
be the port number DatagramServer announced on startup.

When I run this, I get no errors, but the server never
reports having received a datagram and thus never exits.

-T

* * * Code follows * * *

import java.io.*;
import java.net.*;
import java.util.*;
import sun.net.*;

class DatagramServer {
    public static void main(String argv[]) {
	try {
	    DatagramSocket s = new DatagramSocket();
	    System.out.print("Datagram Server listening on port:");
	    System.out.println(s.getLocalPort());
	    byte buf[] = new byte[10];
	    DatagramPacket dp = new DatagramPacket(buf, 10);
	    s.receive(dp);
	    System.out.print("Received from inet address: "
			     + dp.getAddress().toString());
	    System.out.print(" port number: ");
	    System.out.print(dp.getPort());
	    for (int i=0; i<buf.length; ++i)  System.out.println(buf[i]);
	    s.close();
	} catch (Exception e) {
		System.out.println("Something bad happened: server");
	}
    }
}

class DatagramClient {
    public static void main(String argv[]) {
	if (argv.length!=2) {
	     System.out.println("java DatagramClient <hostname> <port#>");
	     return;
	}
	try {
	    int port = Integer.parseInt(argv[1]);
	    InetAddress in = InetAddress.getByName(argv[0]);
	    // InetTuple tup = new InetTuple(in, atoi(argv[1]);
	    DatagramSocket s = new DatagramSocket();
	    byte buf[] = new byte[10];
	    for (int i=0; i<buf.length; ++i) buf[i] = (byte)i;
	    DatagramPacket dp = new DatagramPacket(buf, 10, in, port);
	    s.send(dp);
	    s.close();
	} catch (Exception e) {
		System.out.println("Something bad happened: client");
	}
    }
}

