Use Messenger to implement two-way process communication, servicemessenger
Ideas:
(The server is referred to as the server, and the Access Server is referred to as the client)
1.The Message transmitted between the service process and the client process. Therefore, the server must have a Handler object to process the received Message object.
2. The client sends a Message object to the server. The Messenger object used is transmitted from the server. Similarly, if the service end sends a Message to the client, the Messenger is sent from the client. That is, one end of the response message must provide the Messenger object to the other end.
3. The client sends a message to the server before sending a message to the client as a response.
4. Note: For bidirectional communication, both the server and client must have the Handler object and the Messenger object. The Handler object processes the message and the Messenger sends the message.
In this article, services are bound by implicit Intent. You need to set the Intent action value, which corresponds to the action attribute set in Intent-filter in the server configuration file. You must register the service in the configuration file and set the exported attribute to true. The default value of this attribute is true. false, indicating that the external process cannot access the service.
Steps:
1. Create a Service process and create a Handler object in the Service to process the Message sent by the client. Use this Handler object to create a Messenger object for the client to send messages to the server.
2. Use the Messenger object created in the previous step in the onBind () method to create an IBinder interface object and send it to the client as the return value of the onBind () method.
3. register the service in the configuration file and register a filter.
4. create a client process, create a subclass that implements the ServiceConnection interface on the client, and implement two methods for this interface. In onServiceConnected (ComponentName arg0, IBinder arg1) {} method, create a Messager object using the IBinder interface object parameters passed by the server to send messages to the client.
So far, the client has implemented one-way communication to send messages to the server.
5. If two-way communication is required, create your own Handler object on the client and use this object to create the client's Messenger object.
6. When the client sends a Message, the Messenger object created in the previous step is assigned to the replyTo field of the Message;
7. When the Service side processes a message, it obtains the client-side Messenger encapsulated in the message. With this Messenger object, the server side can send a message to the client.
In-depth Windows Messenger: how to implement communication
Users can also establish communication conversations for instant messaging communication, voice and/or video conversations, collaboration at the same level, or other communication features. Windows Messenger provides these features through supporting a large number of different protocols. Windows Messenger supports the following main servers:. NET Messenger Service: most Windows XP users who use the Home Edition or Pro version will use the. NET Messenger Service. Exchange 2000 IM Server: companies and enterprises choose to use Exchange 2000 IM Server to support their Global Address Book feature. The Server provides IM and Presence support. Ietf sip Proxy Servers: To obtain all RTC functions, companies and enterprises will choose to deploy the SIP-based solution. Protocols to be attached include Session Initiation Protocol (SIP; RFC 2543) and Session Description Protocol (SDP; RFC 2327 ). Windows Messenger can work with multiple types of servers and protocols at the same time. This feature applies to companies that need to use Exchange IM and. NET Messenger for internal and external communications, respectively. Windows Messenger supports the main services supported by Windows Messenger. The main services supported by Windows Messenger include: Presence in Windows Messenger can tell you the online status of all objects in the contact list. When a user logs on to Windows Messenger, Messenger automatically logs on to each configured network. Although each network is different and may use different protocols, users can register Presence on each network. In this process, Windows Messenger will establish an association with Presence and Rendezvous Server. There is a Transmission Control Protocol (TCP) connection between. NET Messenger and Exchange IM. However, the protocol used to provide Presence over TCP connections is different. This connection will be used for communication through the server, including sending IM messages. If the SIP Server solution is used, an association is established between the sip regi ster, su bsc ribe, and consumer y, and the User datagrams Protocol is often used as the transmission carrier. You can add a contact to Windows Messenger by specifying the contact information, including the address and service used. Windows Messenger will register (subscribe) a notification of the Presence and online status updated by the Service set by the contact. After that, the underlying protocol support will register an appropriate server and/or service no matter when you log on to Windows Messenger. After registration, the server and/or service will update users and all contacts in the contact list and display their correct online status. Windows Messenger users can instantly communicate with current online contacts. Online contacts are displayed in green. Instant messaging is a communication and collaboration mode in Windows Messenger. The initialization and communication protocols used in the IM conversation depend on the selected server or service. For. NET Messenger or Exchange IM, the IM text is transmitted over a TCP connection. When using the SIP Proxy server, you can configure the server to use the full text of ......>
What are the three basic types of process communication?
Inter-process communication can be achieved through two basic methods:
(1) using the shared memory area to achieve shared access to data or code segments;
(2) Using the inter-process communication (IPC) tool provided by the system kernel, IPC is provided by the message passing system.
The second method is widely used, especially the Internet-based process communication mechanism. it can also be divided into direct communication and indirect communication. the former requires both parties to clearly specify the receiver and sender, while the latter sends messages through the port (or mailbox.
For more information, see the discussion about Process Communication in <Operating system concepts> Version 6 by Dr. Abraham Silberschatz.