Application of MSMQ technology in Windows Mobile system communication
introduction
With the continuous maturity of 3G network technologies, markets and policies, the use of mobile terminal equipment is rapidly increasing and is widely used in various fields. Windows Mobile is an operating system developed by Microsoft for smart mobile terminal devices. Windows Mobile extends the familiar desktop Windows experience to mobile devices. Windows Mobile provides a simple and safe solution for data exchange and information sharing between mobile terminal devices. The data communication technologies on the Windows Mobile platform include Socket, Web Service, and MSMQ (Microsoft Message Queuing Technology). Socket transmission data will customize the transmission data format and the server will use multithreading to receive client information. The programming is complicated and not easy to control; Web Service programming is simple and easy to control, but it is only possible to call the server function and cannot implement the server and client Mutual communication; MSMQ is an asynchronous communication method provided by Microsoft that can be accessed remotely, supports forwarding, supports delayed transmission, and has high security. It is the most reliable data communication method on the current Windows Mobile platform.
MSMQ technology
Message Queue (Microsoft Message Queue) is an asynchronous transmission mode that realizes mutual communication between multiple different applications (terminals or services). The applications that communicate with each other can be distributed on the same machine or connected. Any terminal in cyberspace. The message is the information that the two parties need to communicate. It can be various objects, such as text, sound, and image. The final implementation of the message is stipulated by the agreement jointly developed by the two parties of the message delivery. The benefits of this method not only encrypt the data, but also reduce the burden of system communication. The implementation principle is that the sender of the message puts the information he wants to send into a container (Message), and then saves it to a message queue in a system common space; the local or remote message receiving program then re-starts from the queue Remove the message sent to it for processing.
Since the asynchronous communication method is adopted, neither the sending program nor the receiving program can execute the remaining code without waiting for the other party to return the sign of successfully sending the message, thereby improving the processing capacity of the system. During the process of information transmission, the information sending mechanism has the ability to recover from failures; MSMQ's message passing mechanism enables both parties to the message communication to communicate through different physical platforms. Using the MSMQ function provided by the operating system that supports .net technology, you can easily create or delete message queues, send or receive messages, and manage message queues. Message queue is a common storage space for sending and receiving messages, it can exist in memory or in physical files.
System structure and software configuration
system structure
For the production field data collection system of the passenger car industry, passenger car production belongs to the mixed flow production industry, with complicated processes and technological routes, more manual participation in production, and larger passenger cars than other products. Therefore, on-site personnel are required to use PDA to scan production data and report production Progress status. The workshop and factory area are large and the workshop environment is complex. The entire network uses wireless communication. The Windows Mobile system is installed in the PDA, and various application programs can be installed in the PDA, such as barcode scanning, workshop material supply and demand programs, and production site scheduling programs. External devices such as barcode scanners and micro printers can also be expanded on the PDA. Using the mobility of PDA and relatively strong data processing ability, the field data can be collected and sorted in real time. Upload the collected field data to the data collection server, production tracking server and production scheduling server.
The system hardware platform shown in Figure 1 is mainly composed of the server, wireless router and PDA data collector of the factory-level data center. The multiple PDA data collectors configured in the workshop according to the production process, the scanner on the PDA can be real-time Collect field data, the processing program on the PDA will process the collected data, and then upload it to the factory-level data center server through the multi-layer wireless router AP, each PDA has its own independent IP address, and the server uploads the data by sending and receiving messages. The data is managed and commands are issued to the PDA. The entire system includes a server program and a client program, and realizes data communication between the PDA and the data server through MSMQ technology.
System software configuration
Server configuration: The server is a Windows Server 2003 operating system. The server program checks the online status of the client and shares online client information (including: client name and client segment IP address) with each client.
Client: You need to set the server-side IP address and local client name. After setting the correct server IP address and local client name. Obtain online client information through the server. After specifying the client, you can receive new messages and send messages.
Application of MSMQ technology in Windows Mobile
To realize data communication through MSMQ technology in the Windows Mobile operating system on the PDA, to use MSMQ to develop a message processing program, a message queue must be installed on the server host and client. The message handler is mainly for sending and receiving messages. If you want to send and receive messages, you must refer to a queue. The referenced message queues are divided into public queues and private queues. These two queues store messages designed by users. After referencing the message queue, you can send, receive, and read messages. The message receiving service is located in System.Messaging, and the System.Messaging.dll file needs to be referenced in the project. The specific implementation process and code are as follows:
Reference queue
The queue is referenced by three methods: path, format name, and label. For example: refer to the message queue through the path, the path is in the form of machinename \ queuename. In practical applications, the path to the queue must be unique. Table 1 lists the path information for each type of queue.
If it is sent to the machine, you can also use "." To represent the name of the machine. The specific reference method can be set when the message queue is initialized, or by setting the Path property of the message queue. If the message queue is referenced during initialization, the message queue must exist in the system, otherwise an error will occur. The message queue can be created in the program.
The code that references the message queue during initialization is as follows:
MessageQueue Mq = new MessageQueue (“. \\ private $ \\ mqâ€);
Code to refer to the message queue through the Path attribute:
MessageQueue Mq = new
MessageQueue ();
Mq.Path = â€. \\ private $ \\ mqâ€;
If the message queue does not exist, you can use the Create method to create the queue on the computer, the implementation code is as follows:
System.Messaging.MessageQueue.
Create (@ ". \ Private $ \ mq");
send messages
After the application refers to the message queue, it can send and receive messages. The messages sent can be divided into simple messages and complex messages. Simple message types are commonly used data types, such as integers, strings, and other data; complex message data types usually correspond to complex data types in the system, such as structures and classes Objects etc.
An example of sending a simple message is as follows:
Mq.Send (1000); // Send integer data
1000
Mq.Send (“This is a test
message! â€); // Send a string
The sending of complex messages is similar to the sending of simple messages, except that when sending, the content of the sent message is usually not directly given, but a variable representing the content of the sent message. The following code sends a complex message through message variables and complex data type variables.
The message sent in the following code is represented by a message variable:
Message Msg;
Msg = new Message ("A Complex
Message! ");
Msg.Label = â€This is the labelâ€;
Msg.Priority = MessagePriority.High; Mq.Send (Msg);
The message sent in the following code is represented by a complex data type variable, and Customer is a custom class:
Customer customer = new
Customer ();
customer.LastName = "Copernicus";
customer.FirstName = "Nicolaus";
Mq.Send (customer);
Receive message
Receiving a message is more complicated than sending a message. There are two ways to receive messages: receive the message through the Receive method and permanently delete the message from the queue; remove the message from the queue through the Peek method without removing the message from the queue. If you know the identifier (ID) of the message, you can also complete the corresponding message receiving operation through the ReceiveById method and the PeekById method.
The code to receive the message is as follows:
Mq.Receive (); // or
Mq.ReceiveById (ID);
Mq.Peek (); // or
Mq.PeekById (ID);
Read news
Only by extracting the information in the received message according to the agreement between the two parties of the communication, the transmitted message is valuable, so after receiving the message, the information contained in the message must also be able to be read. The format of the message sent by the application on the sending end and the transmission message in the message queue are different. Therefore, the message sent by the application on the sending end is serialized before being sent to the message queue. This process is automatically completed by the system and the program is developed. People do not have to write code for this, but after receiving the message, they need to deserialize the received message.
The deserialization of messages can be accomplished through three predefined formatters included with Visual Studio and .NET Framework: XMLMessageFormatter object (the default formatter setting of MessageQueue component), BinaryMessageFormatter object, and AcTIveXMessageFormatter object. Because the formatted messages of the latter two cannot usually be read by users, XMLMessageFormatter objects are often used to deserialize the received messages.
The code to deserialize the message using the XMLMessageFormatter object is as follows:
string [] types = {"System.String"};
((XmlMessageFormatter) mq.Formatter) .TargetTypeNames = types;
Message m = mq.Receive (new
TImeSpan (0,0,3));
After transmitting the received message to the message variable, the message can be read out through the Body property of the message variable m:
MessageBox.Show ((string) m.Body);
Close the message queue
Close the message queue can be achieved by the Close function, the code is as follows:
Mq.Close ();
Conclusion
The high-speed wireless network based on the Windows Mobile platform provides more reliable and convenient mobile solutions for customers in various industries. Message queuing technology ensures good communication between mobile devices and data centers. The message queue technology is simple and practical by explaining the working process of sending, receiving and reading messages on the Windows Mobile platform. The Windows Mobile platform communication system based on MSMQ technology has been applied in the production tracking system of a large domestic bus company.
Esd Tvs Diode,Esd Protection Diode,Esd Suppressor Diode,Usb Esd Protection Diode
Shenzhen Kaixuanye Technology Co., Ltd. , https://www.icoilne.com