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#Copypublic 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
Declaration
C#Copypublic 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
CopyMessagePort messagePort = new MessagePort("SenderPort", true);
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when portName is null or empty. |
API Level: 3
Properties
Declaration
C#Copypublic bool Listening { get; }
Property Value
Type | Description |
---|---|
Boolean |
API Level: 3
Declaration
C#Copypublic string PortName { get; }
Property Value
Type | Description |
---|---|
System.String |
API Level: 3
Declaration
C#Copypublic bool Trusted { get; }
Property Value
Type | Description |
---|---|
Boolean |
API Level: 3
Methods
Declaration
C#Copypublic void Dispose()
API Level: 3
Dispose(Boolean)
Releases the unmanaged resources used by the MessagePort class specifying whether to perform a normal dispose operation.
Declaration
C#Copyprotected 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
Declaration
C#Copyprotected void Finalize()
Declaration
C#Copypublic void Listen()
Examples
CopyMessagePort 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
Send(Bundle, String, String)
Sends an untrusted message to the message port of a remote application.
Declaration
C#Copypublic 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
CopyMessagePort 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
Send(Bundle, String, String, Boolean)
Sends a message to the message port of a remote application.
Declaration
C#Copypublic 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
CopyMessagePort 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
Declaration
C#Copypublic void StopListening()
Examples
CopyMessagePort 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
Declaration
C#Copypublic event EventHandler<MessageReceivedEventArgs> MessageReceived
Event Type
Type | Description |
---|---|
System.EventHandler<MessageReceivedEventArgs> |
Examples
CopyMessagePort 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); } }