// Sender.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved
package com.symbian.devnet.whist.tokenRing;
import javax.net.datagram.*;
import java.io.*;
/**
* A class responsible for initialising as DatagramService to be
* used for sending Datagrams and for using it to send
* Datagrams.
* @author Symbian Devnet
*/
class Sender
{
/**
* The DatagramService through which
* Datagrams are sent.
*/
private DatagramService senderService;
/**
* Constructor which initialises the DatagramService.
* @param a the Address the DatagramService is
* initislised on.
*/
Sender(Address a) throws Exception
{
try
{
senderService = DatagramService.getServerService(a);
}
catch(Exception e)
{
System.out.println("Unable to getServerService.");
System.exit(0);
}
}
/**
* A method allowing Datagrams to be sent using the
* DatagramService.
* @param dg the Datagram to be sent
*/
public void sendToken(Datagram dg) throws Exception
{
try
{
senderService.send(dg);
}
catch(Exception e)
{
System.out.println("Address not supported.");
System.exit(0);
}
}
}