Tip:
Highlight text to annotate it
X
Hi All, in this session we are going to discuss communication options available in bada. We
will discuss Network, Telephony & Messaging in detail.
I will be covering supported inter communication technologies like HTTP, Wi-Fi, Bluetooth ,DNS,
Sockets, Near Field Communication, Telephony and Messaging. These are explained in detail
in further slides. This video lecture explains about various
features like network account and connection management.
Messaging namespace includes SMS, MMS, Push messaging and E-mail.
Telephony mainly covers features of Call, Network and SIM.
There are many other name spaces too, which have been explained in this video lecture
like Sockets, Bluetooth, Wi-Fi, HTTP and NFC.
The HTTP client architecture provides a generalized mechanism for HTTP-like protocols that operate
over various transport layer protocols.
Using this namespace, a client can choose an HTTP protocol, encode the data and then
transport it. The default operation provides plain-text
HTTP operating over a TCP/IP connection. Plain-text HTTP is explained in RFC 2616.
Using HTTP namespace, a client can choose an HTTP protocol, encode the data and then
transport it. Key features used in HTTP protocol implementations
are multi-session and multi-transaction. This protocol implementation mostly includes
HTTP 1.1 client feature like connection management, pipelining and
chunking. HTTP namespace handles cookies received by
the server as part of any particular HTTP instance.
Authentication class handles client's HTTP authentication activity over the duration
of a single transaction. There are various other features like HTTP
Redirection, Multipart and URL Encoder/Decoder Support that are included in this name space.
HTTP Privilege is needed in order to use the HTTP APIs.
A session encapsulates the client's HTTP activity over the duration of the client's execution.
It is a set of transactions using the same connection settings such as proxy. The client
may use several sessions concurrently if desired. A transaction represents an interaction between
the HTTP client and the HTTP origin server. Normally, a transaction consists of a single
exchange of messages between the client and server: A client requests and server responds.
A transaction encapsulates a request and a response.
HTTP Request class represents an HTTP request message which stores a method (for example,
HTTP GET), and a URI, as well as the other message headers and body supplied by the HttpMessage
base class. Http Response class represents a response
message which stores a status code, status text, and server version information, as well
as the message headers, and body supplied by the HttpMessage base class.
This diagram explains basics of HTTP protocol. HTTP Session comprised of HTTP Transaction.
HTTP Transaction is comprised of Request and Response.
Lets see the steps to be followed for the Http session creation and establishment.
This includes construction of http session with target host address & open a transaction
of the session. Add a transaction listener and get a request
from the transaction & set it up. IHttpTransactionEventListener interface provides
listeners for Http transaction events. OnTransactionReadyToRead listens to the read
body event & notifies when content of the body has been received.
The subsequent slides explain the HTTP session creation or establishment and listener functionality
with the help of examples. This code explains the http session creation,
opening of transaction and adding transaction listener.
First, I have created an object for the HttpSession class.
Then constructed the HttpSession class object with the required arguments i.e HTTP session
mode, proxy address, host address and a null argument for common HTTP header.
After that I have created a transaction of the session.
Then added a transaction listener to the transaction object.
Now, lets see how to send an HTTP request. First, I have taken the pointer of Http request
so that we can use various methods of this object.
Then I have set the URI as ﹒http://www.bada.com‧. After that I have taken the header and added
required info to it. AddField() adds a named field, which is a
pair, to the current instance of HttpHeader.
Once the header addition is completed, I have submitted the request to server by calling
the submit method.
In this sample we will see the implementation details for the listener OnTransactionReadyToRead
. This listener is called when the content body
of the HTTP response has been received. Check the status code of the HTTP response.
If it is OK, then it means that the HTTP response has been received correctly.
Then get the header by using API GetHeader() and read the body of the information received
by using API ReadBodyN() . Here I explain HTTP Multipart upload implementation.
First, [to the narrator: on 1st click]I have created
and initialized the object of the pMultipartEntity. Then added
[to the narrator: on 2nd click] various format used like string & file in multipart.
After that [to the narrator: on 3rd click]I have set
multipart entity to the HTTP request, and then submitted the request with submit method.
Lets discuss about the DNS class now. This class represents a request for information
from a DNS server. The Domain Name System makes it possible to
assign domain names to groups of Internet resources and users in a meaningful way, independent
of each entity's physical location. This class supports DNS lookup and requires
NET privilege. A DNS request can be one of the two types,
represented by GetHostByAddress() and GetHostByName(). GetHostByAddress() represents a request for
DNS lookup for a host by providing its IP address as argument.
GetHostByName () represents a request for DNS lookup for a host by providing its name
as argument e.g. www.bada.com. Both requests can be made in an asynchronous
mode. IDnsEventListener interface implements listeners
for DNS events. OnDnsResolutionCompletedN is used to notify
the result of DNS request. In this API, it is recommended to always check
the error code before accessing the result. If result is not ﹐success﹑ then IpHostEntry
may not exist. This slide explains pseudo code implementation
for Dns class. Initialization of object has been done in
foo () function. Sending a request to get host by name is implemented
in this slide. [to the narrator: on 1st click] First, constructs
& initializes an object of Dns class. [to the narrator: on 2nd click]then, using
GetHostByName, requests a DNS lookup by host name.
This method is asynchronous. OnDnsResolutionCompletedN is used to notify
the result of Dns request.
A socket is a communication mechanism, which was first introduced in the 4.2 BSD Unix systems
in 1983. A socket is one endpoint of a two-way communication
link between two programs running on the network. The Sockets namespace is a part of the Net
namespace, which implements socket data communication protocols.
It provides a rich set of methods for connecting, sending, and receiving data over a network.
The Socket class provides methods for standard BSD-style socket calls.
For example, using the TCP socket, clients connect to a server and the server listens
for new connections from the clients. Once a connection is established, data can be sent
or received. There are two communication mechanism used
here - synchronous and asynchronous. Synchronous communication is also known as
blocking mode. As we know that to achieve synchronization, application may be paused.
Asynchronous communication is non-blocking mode.
App using socket implementation should use Socket privilege.
Various methods given in this class are connection establishment, synchronous transfer, asynchronous
transfer and connectionless transfer. Connect() establishes a connection to a remote
host for a connection-oriented socket. This socket is of the NET_SOCKET_TYPE_STREAM
type. AcceptN(), accepts an incoming connection.
Extracts the first connection from the queue of pending connections, and creates a new
socket with the same socket type, protocol type, and protocol family as the listening
socket. The ISocketEventListener interface specifies
the methods used for notifying different kinds of socket events.
These events are only sent out while using the socket in a non-blocking mode.
A listener is registered by calling AddSocketListener(). One of these methods is called when a socket
event is generated. In this slide I have explained the method
to work on the Socket client. First we have to construct a socket client
and put it in the blocking mode. Then we need to connect to the remote host.
socket->Connect() , establishes a connection to a remote host for a connection-oriented
socket. socket->Send () & socket->Receive () are used
for sending data to a socket of the type NET_SOCKET_TYPE_STREAM & receives data from a socket of type NET_SOCKET_TYPE_STREAM.
Once sending and reception has been completed, we can close socket by using API socket->Close().
Here is an example which explains the socket creation and setting connection.
This code explains socket initialization with non-blocking mode.
Then it has been connected to host address 202.30.31.60 .
Connect() API is used for connecting to other end point.
This slide explains sending of the data to peer.
Send() API is used to send the data for newly created socket. Sends data to a socket of
the type NET_SOCKET_TYPE_STREAM. The point to be noted is, the Send() method
sends data to the remote host specified in the Connector Accept() method. The Send()
method sends data in the buffer until length, starting from the current position of the
buffer. The Send() method can be used only for connection-oriented
sockets. In the blocking mode, if there is no space
left in the send queue, the socket blocks until space becomes available.
This slide explains about the reception of data.
First we allocate space an array of size 1 Kb.
The Receive() method copies data into the buffer parameter, starting from the current
position of the buffer. After the operation, the position of the buffer
is incremented by the number of bytes successfully received.
The new position cannot be larger than the original limit.
You can only call Receive() from connection-oriented sockets.
If no data is available at the socket and the socket is in the blocking mode, this method
blocks until data arrives. After completion of job, socket should be
closed and the memory should be released. Now I will explain the pros and cons of blocking
mode transfer of data. blocking mode is easy to develop and to understand.
There is no complicated communication synchronization. But it can freeze the application, in case
response is not received from the host. Delay in transmission gives the picture of
freezed application. Here we are coding for the sending and receiving of data in non-blocking
mode. Create a connection-oriented socket.
Create and add listener. Call socket->Connect(). On receiving connection
response, the listener function will get invoked. Here we have implemented listener functionality.
We have created a class in which required data is maintained for the implementation
of the listener. Variables such as Total length to send and
receive have been declared. OnSocketConnected notifies a connecting socket
that its connection attempt has been completed successfully.
Once socket is successfully connected, we can start sending data.
Here I have explained about OnSocketReadyToSend event implementation.
OnSocketReadyToSend notifies a socket that the data can be sent.
We need to check whether the socket is in sending mode before sending something over
the socket. We can send data only if it is in sending mode.
In this sample, If all data has not been sent, I have set the status as 1 so that data sending
will be repeated In this slide I have implemented ready to
receive functionality. OnSocketReadyToReceive event notifies a socket
that the data is ready to be retrieved. Here, First I am checking whether the socket
is in receiving mode. If yes, I start receiving the data.
If not all data has been received, I am returning the control to receive more data.
When whole data is received, we will close the socket.
OnSocketClosed method notifies the registered socket that the peer socket has been closed
due to normal or forced termination of network. It is also used to notify a connecting socket
that its connection attempt has resulted in an error.
Secure socket class provides the SSL supported socket with security features.
It is nearly similar to normal socket except it supports only non-blocking mode.
It is used for connection oriented socket only.
It bypasses listening and accepting & it supports client mode only.
Wi-Fi is a wireless local area network that links two or more computers or devices based
on the IEEE 802.11 specification, that enables communication between devices
in a limited area. Wi-Fi Direct is a technology to communicate
among Wi-Fi devices without wireless access points
or base stations in an infrastructure mode. It provides a rich set of methods to manage
Wi-Fi devices and accounts, and to communicate over a Wi-Fi channel.
A Wi-Fi is a type of local-area network that uses high-frequency radio waves instead of
wires to communicate between devices. It provides a rich set of methods for managing
Wi-Fi devices and accounts; and communicating over a Wi-Fi channel.
WiFi operates in two modes as explained i.e. Infrastructure mode and Ad-hoc mode.
The image shows an example of infrastructure mode, where-in mobile phones having Wi-Fi
capability are connected to each other using a Wi-Fi access point.
A Wi-Fi client must use the same SSID as the AP of WLAN, to join the network.
The image shows an example for Ad-hoc mode where-in the Wi-Fi enabled mobile devices
and laptops are connected ,without the use of an access point.
In this mode, the devices can directly communicate with each other.
In Ad-hoc mode, all the Wi-Fi peers need to use the same SSID and channel number.
For working on Wi-Fi application, we have to set the privilege to WI-FI.
WifiManager class provides the functionality for creating an instance of Wi-FiManager,
and managing local Wi-Fi devices. It also allows the listener to get events
from local Wi-Fi devices. Here I have created an instance of Wi-Fi Manager
and listener for the same. Wi-Fi Manager is initialized and activated
using Construct, Activate methods. Current status of connection to a specific
access point is verified using IsConnected method.
Deactivate() is used to deactivate the local Wi-Fi device.
This slide explains simple adhoc network service. adhocListener is used to create a listener
object and then adhocService() is used to create a service.
GetNeighborsN gets the neighboring peers' information.
If it is valid for all neighboring peers then get the name and address of all peers.
SendBroadcastmessage is used to send a broadcast message to all the peers in Ad-hoc network.
To stop an Ad-hoc service, StopAdhocService method is invoked.
Further in this slide we have various listener methods for an Ad-hoc network.
OnAdhocServiceStarted is the event handler used to notify that the ad hoc service has
started. OnAdhocServiceStopped is received, once the
StopAdhocService method is executed. Similarly, OnMessageReceived is used to notify
, when a message is received by the device.
Wi-Fi direct is explained very clearly in this slide.
Wi-Fi Direct, formerly known as Wi-Fi Peer-to-Peer, is a set of software protocols that allow
Wi-Fi devices to talk to each other without the need for wireless access points or hot
spots. Using Wi-Fi direct, it is easy to share, show
,print and synchronize content. As we know that Wi-Fi is developed and supported
by the Wi-Fi alliance who developed Wi-Fi certified standards.
Adhoc is normal Wi-Fi service which involves AP, whereas Wi-Fi direct doesn﹑t involve
physical access point.
Wi-Fi Direct functionalities are provided to manage the Wi-Fi Direct device and group.
WifiDirectDeviceManager class provides methods to create instance of WifiDirectDevice and
to manage Wi-Fi Direct functionalities. Here are some of the methods provided by this
class.
To activate and deactivate a Wi-Fi Direct device we can use Activate and Deactivate
methods. Creating a Wi-Fi group is achieved through
CreateGroup API. To scan Wi-Fi Direct devices, Scan API is
used. To associate to a Wi-Fi Direct group owner,
one needs to invoke Associate API The Wi-Fi Direct Device and Wi-Fi Direct Group
listeners have various methods associated to notify various events.
OnWifiDirectAssociationCompleted notifies the completion of association of a device
with a group owner. Activation and Deactivation of devices are
notified by the
methods OnWifiDirectDeviceActivated() and OnWifiDirectDeviceDeactivated() respectively.
When a Group is created, the event is notified by a OnWifiDirectGroupCreatedN() method. OnWifiDirectScanCompletedN
notifies the completion of Wi-Fi direct scan.
Group Owner gets notified of client association and disassociation via OnWifiDirectClientAssociated()
and OnWifiDirectClientDisassociated() OnWifiDirectGroupDestroyed is invoked when
WifiDirect group is destroyed.
Starting and stopping of Group member info service is notified via OnWifiDirectGroupMemberInfoServiceStarted
and OnWifiDirectGroupMemberInfoServiceStopped .
OnWifiDirectAllGroupMemberInfoReceivedN method is invoked on IWifiDirectGroupClientListener
listener to notify that the Wi-Fi direct client has received all the group member information.
Similary OnWifiDirectGroupOwnerInfoReceived notifies that the information about Group
Owner is received by the Wi-Fi direct client. The termination of association of a client
with Group Owner is notified by OnWifiDirectAssociationTerminated. The Bluetooth namespace provides mechanism
for peer to peer communication. The Bluetooth is a sub-namespace of the Net
namespace. It implements the Bluetooth data communication protocols.
It provides a rich set of methods for connecting, sending, and receiving data over a Bluetooth
connection.
This namespace implements the Bluetooth data communication protocols.
It provides a rich set of methods for connecting, sending, and receiving data over a Bluetooth
connection. The Bluetooth namespace consists of sub-modules
to support different profiles such as GAP, OPP and SPP.
General Access profile provides base for other profiles & it helps two Bluetooth devices
to discover and connect. Object Push Profile is used to send objects
like pictures & audio files. It is called push, as it is instigated by
sender rather than receiver. Serial Port Profile , it emulates a serial
cable to provide a simple substitute for existing RS-232.
To use profile specific to Bluetooth we have to set privilege BLUETOOTH in manifest file.
This example explains about SPP initiator. Bluetooth Manager & initiator object creation
has been implemented in this code segment Bluetooth Manager is responsible for the activation
of the Bluetooth services, which is activated by calling
btManager.Activate(). Once Bluetooth is activated ,we have to get
info of the paired device list as it is shown in the code
using GetPairedDeviceListN(). Once we got the paired device list, we have
to connect it to remote SPP device as shown in the code using connect method
This slide explains declaration of BluetoothSppListener. We have declared virtual functions, which
is to be overridden in this class. OnSppConnectionResponded notifies when a SPP
acceptor responded to the connection request. OnSppDataReceived notifies when the data has
been received and OnSppDisconnected notifies that the connection
is disconnected. The Near Field Communication (NFC) allows
simplified transactions, data exchange, and connections with a touch. It enables devices
to share information within a distance of less than 4 centimeters with a maximum communication
speed of 424 kbps. The NFC enabled devices use the 13.56 MHz radio frequency during communication.
The Near Field Communication service is a set of short-range wireless technology service.
It also includes the contactless card technology ,vicinity card known as RFID technology, and
near field communication technology In bada, NFC read/write mode is supported
and in read write mode , the device is capable of reading and writing NFC forum-mandated
tag , such as in the scenario of reading an NFC Smart Poster tag.
The read/write mode on the RF interface is compliant to the ISO 14443, ISO15693 and FeliCa
schemes. Using event injector in emulator, we can to
simulate the NFC modes
In this slide, we are creating the NFC Manager instance and registers various event listener
of the NFC Manager. IsTagConnected is used to find the tag connection
status. Then GetCurrentTagConnectionN() is used to
get the tag connection with the currently detected tag.
AddTagDiscoveryEventListener is registered with the NFC Manager instance, to get notified
when Tag is discovered. AddNdefMessageDiscoveryEventListener is registered
to get notified when NDEF Message is discovered.
OnNfcTagDetectedN is invoked when a Tag is detected within the vicinity.
OnNfcTagLost method notifies about the lost Tag connection.
When a Ndef Message is detected, the event is notified by the OnNdefMessageDetectedN
method. Messaging is one of the domain namespaces
of bada. Its main purpose is to access the messaging capabilities of the device. It consists
of many methods to perform different tasks such as sending SMS, MMS, email messages,
receiving SMS messages, retrieving SMS messages from the specified message box, and receiving
push messages. Lets check the messaging class. Main feature
includes sending and receiving SMS/MMS/Email. Searching of SMS messages in Inbox/outbox/sentbox
is also described in this slide. This supports reception of push messaging,
in order to use the push messaging service, component setup should be executed.
We have explained about sending a message programmatically. Steps has been clearly mentioned
as implementing a SMS Listener and message event listener.
Create instance for listener. We need SmsManager instance to manage SMS. Set the message body
text. Create a recipient list and add recipients. Send the message with recipients.
Here we have explained coding part as it was explained in previous slide.
this line explains creating an object of Listener instance.
Here, we call constructor of SmsManager instance with listener as the input to check the status
of the message being sent/received. here we construct a message instance with
body text and populate the message recipients.
Once message body is ready, we can send the message using the Send method.
This slide explains SMS Listener class declaration. We have added two methods OnSmsMessageReceived
and OnSmsMessageSent in this class declaration. OnSmsMessageReceived() handles the incoming
sms message. OnSmsMessageSent() Called when the SMS message
is sent. This is a sample implementation of OnSmsMessageSent.
Once the message is sent the message ﹒SMS message sent successfully‧ will be displayed.
This is a sample implementation OnSmsMessageReceived method. This API handles incoming messages.
We can get text of message into string and operate on it.
Here we have explained searching SMS in inbox .
Create SmsMessageListener object and create a SmsManager instance with listener as the
callback to check the status of the message being sent/received.
SearchMessageBoxN is the method which helps us in searching the SMS messages by keyword
in the specified message box. Some points to be noted while using this method is that
the search with the specified keywords searches using only the first 50 characters of the
body text. The SMS messages in the searched result contain only 160 bytes for the body
text. Here I have explained about push message receiving
. Whenever we have to implement push messaging
we need an instance of PushMessageListener then we create an object of the pushmanager
and initializes it. finally, to register the push messaging service
for the current application, we use RegisterPushService method.This method is asynchronous.
Here I have explained push message listener. In this slide I have declared PushMessageListener
class. I have to implement my version of IPushManagerListener and IPushEventListener.
OnPushServiceRegistered() notifies the result of PushManager::RegisterPushService().
OnPushServiceUnregistered() notifies the result of PushManager::UnregisterPushService().
OnPushMessageReceived() handles the incoming push message from the server.
The Telephony namespace is one of the domain namespaces of the framework. Its main purpose
is to help accessing the telephony capabilities of the device. It consists of many methods
that are responsible for performing different tasks such as providing access to the call
facility, providing network query services, and providing access to the SIM module.
The Telephony namespace is one of the domain namespaces of the framework. Its main purpose
is to help accessing the telephony capabilities of the device. It consists of many sub-methods
that are responsible for performing different tasks, such as providing access to the call
facility, providing network query services, and providing access to the SIM module.
Here I have explained sample code for the call status and call type.
First , I constructed an object for the CallManager. then, GetCurrentCallStatus() is used to get
the call status of the current call. and GetCurrentCallType is used to get the
call type of the current call.
This sample code explains how to get the network information .
First we have to construct an object of the NetworkManager
and get the status of the network by using GetNetworkStatus APIs.
IsCallServiceAvailable() is used to verify the availability of call service.
IsDataServiceAvailable() is used to verify the availability of data service.
IsRoaming() is used to check, whether the current network is in roaming status or not.
Then, GetNetworkInfo is used to get the network information.
In this example, I have explained how to get SimInfo.
first we created & initialized an object of the named SimInfo.
then, GetMnc can be used to get the MNC , ie: Mobile Network Code of the SIM.
GetMcc can be used to get the MCC ie: Mobile Country Code of the SIM.
to get the SPN ie: Service Provider Name string of the SIM card, we can use the method GetSpn.
to get the ICC ID ie: Integrated Circuit Card identification of the SIM card we can use
GetIccId. and to get the operator name of the SIM card,
GetOperatorName method can be used.
In communication, we have HTTP class to support communication via HTTP protocol.
Wifi adhoc mode is useful for the communication with the nearby Hosts.
Wi- Fi direct is provided to operate in infrastructure mode.
To communicate with remote host we use socket class.
NFC and Wi-Fi direct has been also included. Telephony has been added to handle call related
operations. Then we have, Messaging which is used for
sending messages like SMS/ MMS/ E-mail and Push messages.
Now we have successfully completed our discussion on communication. Now it is quiz time.
Similarly there are pros & cons for Non-blocking mode too. In the non-blocking mode, receive
and send will be detected immediately. Steps to implement non ? blocking mode transfer
is to create a socket in a non ? blocking mode.
After adding a listener, send and receive data happens asynchronously.