Java Reference
In-Depth Information
public static void main(String[] args) {
String address # "127.0.0.1";
String name # "Server";
if(args.length > 0) address # args[0];
if(args.length > 1) name # args[1];
try {
Server server # new Server(address, name);
// creates and starts the socket listener
DSocketListener socketListener #
new DSocketListener(server);
server.startActivity(socketListener);
} catch (RemoteException re) { re.printStackTrace(); }
}
}
public class RunnerParser extends DParser {
Runner runner # null ; // a reference to the Runner service
public RunnerParser() { }
public DActivity getActivity(String parameters) {
try {
// parses the parameters
StringTokenizer st # new StringTokenizer(parameters);
int path[] # new int [st.countTokens()];
int id # 0;
while (st.hasMoreTokens())
path[id !! ] # Integer.parseInt(st.nextToken());
// creates and initializes an instance of the Runner
// service
runner # new Runner(process, path);
return runner;
} catch (RemoteException re) { re.printStackTrace(); }
return null ;
}
public void decode(String message) {
try {
if (message.indexOf("SPEED") > # 0) {
// decodes the speed value
int speed # Integer.parseInt
(message.substring(6).trim());
runner.setSpeed(speed);
}
} catch (RemoteException re) { re.printStackTrace(); }
}
public StringBuffer encode(DEvent event) {
// encodes the event that notifies a new position
StringBuffer buffer # new StringBuffer();
buffer.append("EVENT " ! event.name ! " ");
Search WWH ::




Custom Search