import java.util.Hashtable;
import java.io.ByteArrayOutputStream;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import com.novell.java.io.EndianInputStream;
import com.novell.java.io.EndianOutputStream;
import com.novell.utility.naming.Environment;
import com.novell.service.ncpext.NCPExtension;
import com.novell.service.ncpext.NCPExtensionInfo;
import com.novell.service.ncpext.NCPExtensionStrings;
public class SendNCPExtReq
{
static byte reply [];
public static void main (String argv[])
{
if (argv.length < 1)
{
System.out.println ("Error: missing parameters");
System.out.println ("Usage: java SendNCPExtReq <servername>");
System.exit (1);
}
try
{
byte[] request = new byte [1];
String serverName = argv[0];
String ncpextName = "ECHO_SERVER";
Hashtable hash = new Hashtable ();
hash.put (
Context.INITIAL_CONTEXT_FACTORY,
Environment.NW_INITIAL_CONTEXT_FACTORY);
Context initCtx = new InitialContext (hash);
NCPExtension ncpext = (NCPExtension) initCtx.lookup (
"Servers/" + serverName + "/NCPExtensions/" + ncpextName);
DirContext ctx = (DirContext) ncpext;
Attributes attrs = ctx.getAttributes ("");
Attribute attr = attrs.get (
NCPExtensionStrings.NCPEXTENSION_ATTRIBUTE_ID);
NCPExtensionInfo info = (NCPExtensionInfo) attr.get ();
System.out.println ("Name: " + info.getExtensionName ());
System.out.println (
"ID : " +
Integer.toHexString (info.getExtensionID ()));
System.out.println (
"Ver : " +
String.valueOf (info.getMajorVersion ()) +
"." +
String.valueOf (info.getMinorVersion ()));
System.out.println ("Rev : " +
String.valueOf (info.getRevision()));
EndianOutputStream endianOut;
ByteArrayOutputStream byteOut;
EndianInputStream in;
byteOut = new ByteArrayOutputStream ();
endianOut = new EndianOutputStream (byteOut);
endianOut.writeLoHiInt (1);
endianOut.writeLoHiInt (1234);
reply = ncpext.send (byteOut.toByteArray (), 4);
in = new EndianInputStream (reply);
System.out.println ("Server received " + in.readLoHiInt () +
" (should be 8) bytes");
byteOut = new ByteArrayOutputStream ();
endianOut = new EndianOutputStream (byteOut);
endianOut.writeLoHiInt (2);
byteOut.write ((new String ("Hello")).getBytes ());
reply = ncpext.send (byteOut.toByteArray (), 4);
in = new EndianInputStream (reply);
System.out.println ("Server received " + in.readLoHiInt () +
" (should be 9) bytes");
} catch (Exception e)
{
System.out.println ("Exception occured: " + e);
e.printStackTrace ();
}
}
}