Any advice, please!
Shicheng
===========================the error message===============
Q:\STAFF\cmsst1\JavaDistributedObjects\SourceCode\Chpt_15\Listings>java
RMIServe
r
java.security.AccessControlException: access denied
(java.net.SocketPermission 1
27.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown
Source)
at java.security.AccessController.checkPermission(Unknown
Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket
(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket
(Unknown S
ource)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown
Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown
Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at RMIServer.main(RMIServer.java:17)
=========================================================
======================the sample code====================
import java.rmi.*;
import java.rmi.server.*;
public class RMIServer extends UnicastRemoteObject
implements ScoresServerInterface
{
static final String SERVERNAME = "scores";
Scores theScores = new Scores();
public static void main(String [] args)
{
System.setSecurityManager(new RMISecurityManager());
try
{
RMIServer server = new RMIServer();
Naming.rebind(SERVERNAME, server);
System.out.println("Server ready.");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public RMIServer() throws RemoteException
{
theScores.putScore(new Score("Denver", "Broncos",
"Dolphins", 6, 0, 1));
theScores.putScore(new Score("Dallas", "Cowboys",
"Packers", 6, 6, 2));
}
public String [] fetchGames() throws RemoteException
{
return theScores.getGames();
}
public Score fetchScore(String game) throws RemoteException
{
return theScores.getScore(game);
}
}
===============================================
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.rmi.*;
import java.rmi.server.*;
public class RMIClient extends Applet
{
static final String URL = "rmi://localhost/scores";
Button theFetchGames = new Button("Fetch Games");
Button theFetchScore = new Button("Fetch Score");
Choice theGames = new Choice();
TextArea theScore = new TextArea(20, 64);
FetchScoreHandler theFetchScoreHandler =
new FetchScoreHandler();
public void init()
{
setLayout(new BorderLayout());
Panel p = new Panel();
add(theGames, BorderLayout.NORTH);
add(theScore, BorderLayout.CENTER);
add(p, BorderLayout.SOUTH);
p.setLayout(new GridLayout(1, 0));
p.add(theFetchGames);
p.add(theFetchScore);
theScore.setEditable(false);
theScore.setFont(new Font(
"Monospaced", Font.BOLD, 12));
theGames.addItemListener(
new GameHandler());
theFetchGames.addActionListener(
new FetchGamesHandler());
theFetchScore.addActionListener(
theFetchScoreHandler);
}
public void fatalError(Exception ex)
{
ex.printStackTrace();
}
class GameHandler implements ItemListener
{
public void itemStateChanged(ItemEvent evt)
{
String choice = theGames.getSelectedItem();
theFetchScoreHandler.fetchScore(choice);
}
}
class FetchGamesHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
try
{
theGames.removeAll();
ScoresServerInterface server =
(ScoresServerInterface) Naming.lookup(URL);
String [] games = server.fetchGames();
for (int i = 0; i < games.length; i++)
{
theGames.addItem(games[i]);
}
}
catch (Exception ex) { fatalError(ex); }
}
}
class FetchScoreHandler implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
fetchScore(theGames.getSelectedItem());
}
public void fetchScore(String game)
{
try
{
ScoresServerInterface server =
(ScoresServerInterface) Naming.lookup(URL);
Score score = server.fetchScore(game);
theScore.setText(score.toString());
}
catch (Exception ex) { fatalError(ex); }
}
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
AlexV
"Shicheng" <S.T...@shu.ac.uk> wrote in message
news:8pnup6$g5d$1...@nnrp1.deja.com...
C:\Program Files\JavaSoft\JRE\1.3\lib\security
and it works!!!
Shicheng :-) :-) :-) :-)
grant {
permission java.net.SocketPermission "*:1024-65535", "listen,
accept, connect, resolve";
};
========================================================
In article <VVLv5.5348$lD2.1...@weber.videotron.net>,