Problems with kaffe 0.8.1

Yaron Zabary yaron at netaccess.co.il
Mon Feb 24 11:34:29 PST 1997


Hello all,

  The following code works with JDK 1.0.2 (Solaris 2.5.1), but fails with
kaffe 0.8.1 (FreeBSD 2.1.5). This is a simple server. It just listens to
connections on the specified port. Try to connect twice to this port (I
used a C client, but a simple telnet will do). The second time will fail
with the following message: 

java.lang.NullPointerException
        at java/io/PrintStream.print(line unknown, pc 0x184568)
        at java/io/PrintStream.println(line unknown, pc 0x18508d)
        at java/lang/Throwable.printStackTrace(line unknown, pc 0x184479)
        at Server.main(34)



-- Yaron.
-------------- next part --------------

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

class Server {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        boolean listening = true;
        System.out.println(" Server started at " + (new Date()).toString());
        try
	  {
            serverSocket = new ServerSocket(Integer.parseInt(args[0]));
          } catch (IOException e) {
            System.err.println("Could not listen on port: " + e.getMessage());
            System.exit(1);
        }

        while (listening)
	  {
            Socket clientSocket = null;
            try {
                clientSocket = serverSocket.accept();
            } catch (IOException e) {
                System.err.println("Accept failed: " + e.getMessage());
                continue;
            }
            ServerThread t1 = new ServerThread(clientSocket);
            try
	      {
		t1.setPriority(4);
                System.out.println(" Connect from: " + clientSocket.getInetAddress());
	        t1.start();
	      } catch (Exception e) {e.printStackTrace();}
	    }
        try
	  {
            serverSocket.close();
          } catch (IOException e) {
            System.err.println("Could not close server socket." + e.getMessage());
        }
    }
}

class ServerThread extends Thread {

Socket socket = null;
String host = null;
int port = 0;
DataInputStream is = null;
DataOutputStream os = null;

ServerThread(Socket socket)
  {
     super();
     this.socket = socket;
  }

public void run()
  {
        String line = null;
        try
	  {
	    int i = 0;
	    is = new DataInputStream(socket.getInputStream());
	    os = new DataOutputStream(socket.getOutputStream());
            String username = is.readLine();
            String password = is.readLine();
            System.out.println(" user is " + username + "/" + password);
            while(true)
	      {
                line = is.readLine();
                if (line == null) throw new IOException("EOF");
		System.out.println(" Line " + i++ + line); 
	      }
	  } catch (IOException e) { System.out.println(" ended.");}
  }
}




More information about the kaffe mailing list