Skip to content
CaffeinatedRat edited this page Apr 3, 2013 · 1 revision

This method pings the Minecraft WebSocketServer.

Method Signature

The following is the method signature:

CaffeinatedRat.Minecraft.WebSocketServices.prototype.ping(parameters)

Parameters

The following parameters are available for this method:

connectedCallback

This is a callback function that is called when the client-side library has made a successful connection with the WebSocketServer.

  • Value: function() { }
  • Default: Do nothing.

disconnectedCallback

This is a callback function that is called when the client-side library has made a connection has been lost with the WebSocketServer.

  • Value: function() { }
  • Default: Do nothing.

serverTimeCallback

This is a callback function that is called when there is a time update for the WebSocketServer.

  • Value: function(serverTime) { }
  • Default: Do nothing.

updateTime

This parameter is used to determine the amount of time in milliseconds that the ping service will ping the WebSocketServer. This replaces the pingInterval specified during instantiation.

  • Value: 0 - 2147483647
  • Default: 15000 (milliseconds)

Example

//Respond to a server connection.
function pingConnected() {

	console.log("We're online!");

}

//Respond to a server disconnection.
function pingDisconnected() {

	console.log("We've lost connection!  Pancake!");

}

//Respond to the server time update event.
function pingServerTime(serverTime) {

	console.log("The time is " + serverTime + " on the server.");

}

//Ping the server.
wss.ping({
	connectedCallback: pingConnected,
	disconnectedCallback: pingDisconnected,
	serverTimeCallback: pingServerTime
});