Class MessagePort

Definition

Namespace:
Tizen.Applications.Messages
Assembly:
Tizen.Applications.MessagePort.dll
API Level:
3

The message port API provides functions to send and receive messages between applications.

C#
Copy
public class MessagePort : IDisposable
Inheritance
MessagePort
Implements
System.IDisposable
Remarks

The message port API provides functions for passing messages between applications. An application should register its own local port to receive messages from remote applications. If a remote application sends a message, the registered callback function of the local port is called. The trusted message-port API allows communications between applications that are signed by the same developer(author) certificate.

Constructors

View Source

MessagePort(String, Boolean)

Initializes the instance of the MessagePort class.

Declaration
C#
Copy
public MessagePort(string portName, bool trusted)
Parameters
Type Name Description
System.String portName

The name of the local message port.

Boolean trusted

If true, it is the trusted message port of application, otherwise false.

Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true);
Exceptions
Type Condition
System.ArgumentException

Thrown when portName is null or empty.

API Level: 3

Properties

View Source

Listening

If true, the message port is listening, otherwise false.

Declaration
C#
Copy
public bool Listening { get; }
Property Value
Type Description
Boolean
API Level: 3
View Source

PortName

The name of the local message port.

Declaration
C#
Copy
public string PortName { get; }
Property Value
Type Description
System.String
API Level: 3
View Source

Trusted

If true, the message port is a trusted port, otherwise false.

Declaration
C#
Copy
public bool Trusted { get; }
Property Value
Type Description
Boolean
API Level: 3

Methods

View Source

Dispose()

Releases all resources used by the MessagePort class.

Declaration
C#
Copy
public void Dispose()
API Level: 3
View Source

Dispose(Boolean)

Releases the unmanaged resources used by the MessagePort class specifying whether to perform a normal dispose operation.

Declaration
C#
Copy
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

true for a normal dispose operation; false to finalize the handle.

API Level: 3
View Source

Finalize()

Destructor of the MessagePort class.

Declaration
C#
Copy
protected void Finalize()
View Source

Listen()

Register the local message port.

Declaration
C#
Copy
public void Listen()
Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true); messagePort.MessageReceived += MessageReceivedCallback; messagePort.Listen();
Exceptions
Type Condition
InvalidOperationException

Thrown when portName is already used, when there is an I/O error.

System.ArgumentException

Thrown when there is an invalid parameter.

OutOfMemoryException

Thrown when out of memory.

API Level: 3
View Source

Send(Bundle, String, String)

Sends an untrusted message to the message port of a remote application.

Declaration
C#
Copy
public void Send(Bundle message, string remoteAppId, string remotePortName)
Parameters
Type Name Description
Bundle message

The message to be passed to the remote application, the recommended message size is under 4KB.

System.String remoteAppId

The ID of the remote application.

System.String remotePortName

The name of the remote message port.

Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true); messagePort.MessageReceived += MessageReceivedCallback; messagePort.Listen(); using (var message = new Tizen.Application.Bundle()) { message.AddItem("message", "a_string"); messagePort.Send(message, "ReceiverAppID", "ReceiverPort"); }
Exceptions
Type Condition
InvalidOperationException

Thrown when there is an I/O error, when the port is not found.

System.ArgumentException

Thrown when there is an invalid parameter.

OutOfMemoryException

Thrown when out of memory.

ArgumentOutOfRangeException

Thrown when message has exceeded the maximum limit(4KB).

API Level: 3
View Source

Send(Bundle, String, String, Boolean)

Sends a message to the message port of a remote application.

Declaration
C#
Copy
public void Send(Bundle message, string remoteAppId, string remotePortName, bool trusted)
Parameters
Type Name Description
Bundle message

The message to be passed to the remote application, the recommended message size is under 4KB.

System.String remoteAppId

The ID of the remote application.

System.String remotePortName

The name of the remote message port.

Boolean trusted

If true, it is the trusted message port of remote application, otherwise false.

Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true); messagePort.MessageReceived += MessageReceivedCallback; messagePort.Listen(); using (var message = new Tizen.Application.Bundle()) { message.AddItem("message", "a_string"); messagePort.Send(message, "ReceiverAppID", "ReceiverPort", true); }
Exceptions
Type Condition
InvalidOperationException

Thrown when there is an I/O error, when the port is not found.

System.ArgumentException

Thrown when there is an invalid parameter.

OutOfMemoryException

Thrown when out of memory.

ArgumentOutOfRangeException

Thrown when message has exceeded the maximum limit(4KB).

UnauthorizedAccessException

Thrown when the remote application is not signed with the same certificate.

API Level: 3
View Source

StopListening()

Unregisters the local message port.

Declaration
C#
Copy
public void StopListening()
Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true); messagePort.MessageReceived += MessageReceivedCallback; messagePort.Listen(); using (var message = new Tizen.Application.Bundle()) { message.AddItem("message", "a_string"); messagePort.Send(message, "ReceiverAppID", "ReceiverPort"); } messagePort.StopListening();
Exceptions
Type Condition
InvalidOperationException

Thrown when messageport is already stopped, when there is an I/O error, when the port is not found.

System.ArgumentException

Thrown when there is an invalid parameter.

OutOfMemoryException

Thrown when out of memory.

API Level: 3

Events

View Source

MessageReceived

Called when a message is received.

Declaration
C#
Copy
public event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
Type Description
System.EventHandler<MessageReceivedEventArgs>
Examples
Copy
MessagePort messagePort = new MessagePort("SenderPort", true); messagePort.MessageReceived += MessageReceivedCallback; static void MessageReceivedCallback(object sender, MessageReceivedEventArgs e) { Console.WriteLine("Message Received "); if (e.Remote.AppId != null) { Console.WriteLine("from :"+e.Remote.AppId); } }
API Level: 3

Implements

System.IDisposable