Java Reference
In-Depth Information
byte[] payload = message.toString();
try {
UDPDatagramConnection conn = null;
conn = (UDPDatagramConnection)"datagram://localhost:1234");
Datagram datagram = conn.newDatagram(payload, payload.length);
} catch(IOException ioe) { ... }
Server mode connections are for receiving (and replying to) incoming
datagrams. To open a datagram connection in server mode, we use a URI
of the following form:
The port number in this case refers to the port on which the local
device is listening for incoming datagrams. Sample code for receiving
incoming datagrams is given below:
try {
UDPDatagramConnection dconn = null;
dconn = (UDPDatagramConnection)"datagram://:1234");
Datagram dg = dconn.newDatagram(300);
while(true) {
byte[] data = dg.getData();
} catch(IOException ioe) { ... }
A signed MIDlet suite which contains MIDlets that open datagram
connections must explicitly request permission to open client connections
or server connections:
MIDlet-Permissions:,, ...
If the protection domain to which the signed MIDlet suite would
be bound grants, or potentially grants, the requested permissions, the
MIDlet suite can be installed and the MIDlets it contains will be able to
open datagram connections. This can be done automatically or with user
permission, depending on the security policy in effect. Whether untrusted
MIDlets can open datagram connections depends on permissions granted
to MIDlet suites bound to the untrusted protection domain.
Search WWH ::

Custom Search