Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ouya Multiplayer API demo

View in_app.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//Create
OuyaLobby lobby = new OuyaLobby(max_players, port, region);
//Connect
OuyaLobby lobby = new OuyaLobby(host, port);
 
lobby.connect(new Callback() {
@Override
public void onMessage(JSONObject json, Acknowledge ack) {
try {
System.out.println("Server said:" + json.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}
}
 
@Override
public void onMessage(String data, Acknowledge ack) {
System.out.println("Server said: " + data);
}
 
@Override
public void onError(ouyaIOException ouyaIOException) {
System.out.println("an Error occured");
ouyaIOException.printStackTrace();
}
 
@Override
public void onDisconnect() {
System.out.println("Connection terminated.");
}
 
@Override
public void onConnect() {
System.out.println("Connection established");
}
 
@Override
public void on(String event, Acknowledge ack, Object... args) {
System.out.println("Server triggered event '" + event + "'");
}
});
//text
lobby.send("Hello Server!");
 
//json
JSONObject object=new JSONObject();
object.put("name", "James Spencer");
lobby.send(object);
View in_app.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
var net = require('net');
var Lobby = require('./lobby.js')
function createLobby(players, protocol, net) {
var lobby = new Lobby(players, protocol, net, port, function(err, host, port) {
 
console.log('Lobby listening on host ' + host + ':' + port);
 
});
 
lobby.on('connect', function(from, event) {
 
console.log(from.playerName + ' connected at ' + event.time.toString());
 
});
 
lobby.on('disconnect', function(from, event) {
 
console.log(from.playerName + ' disconnected at ' + event.time.toString() + ' because ' + event.reason);
 
});
 
lobby.on('action', function(fromgame, from, event) {
 
if (fromgame) { // If non-player action
console.log(from.sender + ' emitted ' + event);
} else {
console.log(from.playerName + ' emitted ' + event);
}
 
});
}
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.