Understand the technical principle of Java class library of "Blazeds Core Library" framework
Blazeds is a Java library and framework that transmits data between clients and servers.It is based on the Adobe Flex development tool and is used to build a wealthy client application.This article will explain the technical principles of the core library of Blazeds and provide some Java code examples.
The Blazeds core library uses a binary protocol called AMF (Action Message Format) to transmit data.AMF is a lightweight byte serialization protocol that seizures the Java object to binary data and quickly transmits between clients and servers.This binary format is more efficient than using XML or JSON and can provide better performance.
In Blazeds, the message is sent and received through the Remote Procedure Call (RPC).To achieve this, Blazeds introduced some core categories to process the transmission and serialization of messages.
The following is an example code that shows how to send and receive messages in Blazeds:
// Create an AMF connection
AMFConnection amfConnection = new AMFConnection();
// Set the server url
String url = "http://localhost:8080/blazeds/messagebroker/amf";
amfConnection.setObjectEncoding(AMFConnection.AMF3);
amfConnection.connect(url);
// Create a service object
AMFService amfService = new AMFService(amfConnection);
// Call the remote method
Object result = amfservice.call ("MyremoteService.myremoteMethod", "Parameter 1", "Parameter 2");
// Treatment the result of returning
if (result instanceof String) {
String response = (String) result;
System.out.println ("Return Result:" + Response);
}
// Turn off the connection
amfConnection.close();
In the above code, first create an AMFConnection object and set the server URL.Create an AMFSERVICE object and use the call method to call the remote method.Finally, handle the return results.
The core library of Blazeds also provides other functions, such as message subscription and push.By using these functions, developers can realize real -time data updates and server -side push.
In summary, the core library of Blazeds is a Java class library and framework for transmitting data between clients and servers.It uses the AMF protocol for data transmission and provides some convenient functions, such as message subscription and push.By understanding the technical principles of the core library of Blazeds, developers can better use this framework to build a powerful wealth client application.