Skip to content
mizzao edited this page Dec 27, 2012 · 1 revision

Java

The client-side Java API is similar to the Server API, except injection is not used (to reduce the number of dependencies needed) and callbacks are slightly different.

public class SomethingClient {
    ClientController cc;
    public SomethingClient(ClientController controller) {
        this.cc = controller;			
    }
    // Other stuff
}

The ClientController interface provides methods to send messages and obtain other information about the assigned HIT and experiment. TurkServer provides the infrastructure to obtain initialized instances of your client class automatically with appropriate HIT information. A wrapper around the client class is created, which handles received messages from the server and triggers the appropriate callbacks.

Callbacks

@StartExperiment
void startExp() {

}

A method with @StartExperiment is called when the client is notified of the experiment being started on the server side.

@StartRound
void startRound(int n) {

}	

A @StartRound method is called with the appropriate round number before the start of each round.

@TimeLimit
void timeLimit() {

}

A @TimeLimit method is triggered on the client side when the experiment time limit expires on the server side.

@FinishExperiment
void finishExp() {

}

A method annotated with @FinishExperiment is called when the server-side code calls the finishExperiment on an ExperimentController.

@BroadcastMessage
void broadcast(Map<String, Object> msg) {
			
}

A method with @BroadcastMessage is called when a broadcast message is received from the experiment, with JSON deserialized to a Java Map. The annotation supports the forms @BroadcastMessage(key='somekey') or @BroadcastMessage(key='somekey',value='somevalue') to be triggered only when such a key or a key with the corresponding value exists in the map. You can define many methods with different annotation parameters to simplify message processing and avoid using a long if/else if/else statements.

@ServiceMessage
void service(Map<String, Object> msg) {

}

A @ServiceMessage receives the same type of message as above, but is only from the server and not from other users. It also supports custom parameters. You should define the protocol of your experiment to use both types of messages accordingly.

Javascript

Similar implementation to the above, except in Javascript. Documentation to be completed...

Clone this wiki locally