Child pages
  • JSPacket

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Hidden
DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY, UNLESS YOU KNOW WHAT YOU'RE DOING.
		THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO EXTRACT CHANGES FROM THE PAGE AND MERGE THEM BACK INTO SERVOY SOURCE


HTML Table
classservoy sSummary
Colgroup Tag
Column
padding0px
width80px

Column

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Property Summary
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#index
Returns the current position in the byte array of the packet.

HTML Table
classservoy sSummary
Colgroup Tag
Column
padding0px
width80px

Column

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Summary
Table Body (tbody)
Table Row (tr)
Table Cell (td)
byte[]
Table Cell (td)
#getByteArray()
Returns the content of the package into a byte array.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
#getHost()
Returns the name of the host that sent the packet.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#getLength()
Returns the length of the packet in bytes.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#getPort()
Returns the port where the packet originated from.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#readByte()
Reads an 8 bits byte value from the packet, starting from the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#readInt()
Reads a 32 bits int value from the packet, starting from the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#readShort()
Reads a 32 bits short value from the packet, starting from the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
#readUTF([length])
Reads a UTF string from the packet, starting from the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#writeByte(number)
Writes one byte into the packet, at the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#writeBytes(array)
Writes an array of bytes into the packet, at the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#writeInt(number)
Writes a 32 bits int into the packet, at the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
#writeShort(number)
Writes a 16 bits short value into the packet, at the current index.
Table Body (tbody)
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
#writeUTF(string)
Writes an UTF encoded string into the packet, at the current index.

HTML Table
idproperty
classservoy sDetail
Colgroup Tag
Column
padding0px
width100%

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan1
Property Details
Table Body (tbody)
idindex
classnode
Table Row (tr)
idname
Table Cell (td)
index
Table Row (tr)
iddes
Table Cell (td)
Returns the current position in the byte array of the packet. The next read/write operation will occur at this position.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)


HTML Table
idfunction
classservoy sDetail
Colgroup Tag
Column
padding0px
width100%

Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan1
Method Details
Table Body (tbody)
idgetByteArray
classnode
Table Row (tr)
idname
Table Cell (td)
getByteArray
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
byte[]
Span
stylefloat: left; font-weight: bold;
idiets
getByteArray
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns the content of the package into a byte array.
Table Row (tr)
idret
Table Cell (td)
Returns
byte[]
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		var bytes = packet.getByteArray();
		application.output('received a packet of length: ' + bytes.length);
		for (var i=0; i<bytes.length; i++)
			application.output(bytes[i]);
		}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetHost
classnode
Table Row (tr)
idname
Table Cell (td)
getHost
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
String
Span
stylefloat: left; font-weight: bold;
idiets
getHost
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns the name of the host that sent the packet.
Table Row (tr)
idret
Table Cell (td)
Returns
String
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetLength
classnode
Table Row (tr)
idname
Table Cell (td)
getLength
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
getLength
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns the length of the packet in bytes.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idgetPort
classnode
Table Row (tr)
idname
Table Cell (td)
getPort
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
getPort
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Returns the port where the packet originated from.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadByte
classnode
Table Row (tr)
idname
Table Cell (td)
readByte
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
readByte
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Reads an 8 bits byte value from the packet, starting from the current index. Advances the index with one position.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadInt
classnode
Table Row (tr)
idname
Table Cell (td)
readInt
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
readInt
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Reads a 32 bits int value from the packet, starting from the current index. Advances the index with 4 positions.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadShort
classnode
Table Row (tr)
idname
Table Cell (td)
readShort
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
readShort
Span
stylefloat: left;
idiets
()
Table Row (tr)
iddes
Table Cell (td)
Reads a 32 bits short value from the packet, starting from the current index. Advances the index with 2 positions.
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idreadUTF
classnode
Table Row (tr)
idname
Table Cell (td)
readUTF
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
String
Span
stylefloat: left; font-weight: bold;
idiets
readUTF
Span
stylefloat: left;
idiets
([length])
Table Row (tr)
iddes
Table Cell (td)
Reads a UTF string from the packet, starting from the current index. If an argument is specified, then it represents the length of the string to read. If no argument is specified, then first a 32 bits int is read from the packet and that will be the length of the string. Advances the index with a number of positions that depends on the length of the read string.
Table Row (tr)
idprs
Table Cell (td)
Parameters
[length]
Table Row (tr)
idret
Table Cell (td)
Returns
String
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteByte
classnode
Table Row (tr)
idname
Table Cell (td)
writeByte
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
writeByte
Span
stylefloat: left;
idiets
(number)
Table Row (tr)
iddes
Table Cell (td)
Writes one byte into the packet, at the current index. The index is advanced with one position.
Table Row (tr)
idprs
Table Cell (td)
Parameters
number
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteBytes
classnode
Table Row (tr)
idname
Table Cell (td)
writeBytes
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
writeBytes
Span
stylefloat: left;
idiets
(array)
Table Row (tr)
iddes
Table Cell (td)
Writes an array of bytes into the packet, at the current index. The index is advanced with a number of positions equal to the length of the written array.
Table Row (tr)
idprs
Table Cell (td)
Parameters
array
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteInt
classnode
Table Row (tr)
idname
Table Cell (td)
writeInt
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
writeInt
Span
stylefloat: left;
idiets
(number)
Table Row (tr)
iddes
Table Cell (td)
Writes a 32 bits int into the packet, at the current index. The index is advances with 4 positions.
Table Row (tr)
idprs
Table Cell (td)
Parameters
number
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteShort
classnode
Table Row (tr)
idname
Table Cell (td)
writeShort
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
void
Span
stylefloat: left; font-weight: bold;
idiets
writeShort
Span
stylefloat: left;
idiets
(number)
Table Row (tr)
iddes
Table Cell (td)
Writes a 16 bits short value into the packet, at the current index. The index is advances with 2 positions.
Table Row (tr)
idprs
Table Cell (td)
Parameters
number
Table Row (tr)
idret
Table Cell (td)
Returns
void
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)

Table Body (tbody)
idwriteUTF
classnode
Table Row (tr)
idname
Table Cell (td)
writeUTF
Table Row (tr)
idsig
Table Cell (td)
Span
stylefloat: left; margin-right: 5px;
Number
Span
stylefloat: left; font-weight: bold;
idiets
writeUTF
Span
stylefloat: left;
idiets
(string)
Table Row (tr)
iddes
Table Cell (td)
Writes an UTF encoded string into the packet, at the current index. First the length of the string is written on 4 bytes, then the string is written. The index is advanced with a number of positions equal to the length of the string plus 4.
Table Row (tr)
idprs
Table Cell (td)
Parameters
string
Table Row (tr)
idret
Table Cell (td)
Returns
Number
Table Row (tr)
idsam
Table Cell (td)
Sample
Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)