/*****************************************************************************
 *                                                                           *
 *         Licensed Materials - Property of IBM                              *
 *                                                                           *
 *         "Restricted Materials of IBM"                                     *
 *                                                                           *
 *         5799-QRY                                                          *
 *                                                                           *
 *         (C) Copyright IBM Corp. 1998                                      *
 *                                                                           *
 *****************************************************************************/
package com.ibm.devtools.SIPNoTE;

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

/**
 * This class represents the client side application which allows the
 * user to logoff of the SIPNoTE system from the local host.  It will
 * not remove any entries for other hosts on which the user is also
 * registered.
 *
 * @author Bill Nagy
 * @version 1.0
 *
 * @see jlogon
 */
public class jlogoff
{
  static Properties props = new Properties();

  public static void main(String[] argv)
  {
    FileInputStream fin;
    int localport;

    try
      {
	fin = new FileInputStream(".sipnote");
	props.load(fin);
      }
    catch (FileNotFoundException e)
      {
      }
    catch (IOException e)
      {
	System.err.println("I/O Error loading .sipnote file --> "+e);
	return;
      }

    localport = (new Integer(props.getProperty("SNClient.jport",
					       "5062")).intValue());

    if (argv.length > 0)
      {
	System.out.println("Usage: jlogoff");
	return;
      }

    JMessage message = new JMessage(new String[] {"UNREGISTER"},
				    System.getProperty("user.name"));

    try
      {
	Socket server = new Socket("127.0.0.1", localport);
	ObjectOutputStream out =
	  new ObjectOutputStream(server.getOutputStream());
	ObjectInputStream in =
	  new ObjectInputStream(server.getInputStream());
	
	out.writeObject(message);
	out.flush();
	
	try
	  {
	    in.readObject();
	  }
	catch (ClassNotFoundException e)
	  {
	  }

	server.close();
      } catch(IOException e)
	{
	  System.err.println("I/O Error --> " + e); //IO Error
	}
  }
}
