O'Reilly logo

J2ME in a Nutshell by Kim Topley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Datagrams

In addition to stream sockets, the CLDC reference implementation contains support for datagrams. Datagrams and stream sockets differ in several ways:

Data stream versus message passing

A stream socket sends a continuous stream of data from a sender to a receiver, with no provision for marking record boundaries. Datagrams are sent in discrete packets; data sent in one packet is never delivered in the same read as data from another packet.

Connection-oriented versus connectionless

When a stream socket is used, a connection, along which all the data flows, is created between the sender and the receiver. As a result, there is no need to specify where each message is going. A datagram socket does not use a connection; each message is individually addressed, and different messages may go to different destinations. Likewise, a datagram socket may receive messages from any number of different sources, but a stream socket receives data from only a single sender.

Reliability

Data sent using a stream socket is guaranteed to be delivered to the receiver, unless the intervening network fails. In that case, the receiver is notified that its connection to the sender has been lost. Furthermore, the individual bytes are delivered in the order in which they were sent, without duplication. A datagram socket makes no such promises. Messages may be lost or duplicated, or may not arrive in the order in which they were sent.

Because they do not incur the relatively large cost of setting up a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required