Adobe Flash Socket Example
May 25, 2010 Hi there, do you have found some Cati Templates? Or otherwise found some working MIBs to build cacti templates for SRX? Cheers Jochen. Jun 08, 2010 Solved: Here's a Cacti host template that I put together, tested on SRX100, started with a smaller template for an EX series so it should be generic. Cacti template.
This code is intended only to convey the basic concepts of a socket policy file server. Adobe does not. Flash Player sockets and.
This article illustrates how to use sockets to communicate between an AIR 2 application and ActionScript code running in Flash Player. The example includes two programs: an Adobe AIR application and a Flash Player application. The Adobe AIR application acts as the server and listens for Transport Control Protocol (TCP) connections on a socket.
Adobe Flash Test
This application uses the ServerSocket class added in AIR 2. (If you aren't already familiar with the TCP protocol, don't worry. You don't really need to know much about TCP to use sockets.) The client Flash Player application runs in a browser and connects to the AIR server application. The programming tasks this article explores include.
ServerApplication.mxml: The main application file. Code in this file creates the server object and sets up the AIR window to display the messages sent by the client. server/Server.as: Serves a single client connection. server/ SocketService.as: Defines a secondary socket server to serve socket policy files requested by Flash Player. ServerApplication-app.xml: The application descriptor file. FlashProfessional/ServerApplication.fla: The Flash project file (used for Flash Professional CS5 only). In this example, the agreement between the client and the server is that the client first writes two integer values to the socket before writing the message proper.
Adobe Flash Update
The first integer declares the length of the message. The second integer is a code used to declare the data type as either 'object' or 'string.' When the receiver gets a new message, it first reads the size header with the readInt method to determine if the entire message has been received. If so, it uses the type code to determine how to read the rest of the message. (Your own scheme can, of course, be far more complex.).
You should always call the socket flush method when you are finished writing a full message. On some operating systems, flush is called automatically between execution frames, but on others, you must call flush or the data is never sent. Because of this difference in behavior, it is good practice to call flush in every case.
Also, since flush is asynchronous, closing the socket immediately after calling flush can prevent all the written data from being sent. Unfortunately, there's no event to tell you when the socket has been completely flushed. You can use a timer to close the socket if the issue affects your application. As long as there are at least 4 bytes available to read (the size of the integer declaring the message length), you do the following: if you haven't already started reading a message (by reading the length header), then you read an integer's worth of data as the message size. If this size is less than or equal to the data available from the socket, then you read the message. Otherwise, you exit from the loop and wait for the next socketData event.
A while loop is used, because more than one message could be available in the socket. In most circumstances, Flash Player requests a socket policy file from the server before it allows code to create a socket connection. The socket policy file describes who can connect to a server and which ports they can access.
When the connect method of a Socket object is called, the Flash Player runtime first opens a separate XMLSocket connection to request a socket policy document from the server. The runtime sends the string, ' over the socket and expects to get back an XML string terminated with a null byte. Your server is no exception to the socket policy. You need to listen for a policy file request and respond with an XML policy document or the client won't be able to connect. This requires our server socket to have two modes: one for handling policy files and the other for handling regular requests. In the first mode, the server socket expects strings that it can read with the readUTFBytes method. The socket looks for one of two strings.
If the string is ', then it responds with a policy file document permitting access. If the string is “BEGIN”, then the socket changes to the second mode.
This handshake logic is implemented with the following function. The default AMF encoder only preserves public properties of an object.
To preserve other properties, you have to write your own custom serialization routines. Also by default, the type information of an object is lost. The remote side of the socket only receives a generic Object.
To preserve the class of an object, you must call the registerClassAlias function in both the sender and the receiver of the object. This function maps a class name string to a class definition. The function call used in both the client and server applications is.
As you can see, the order in which properties are read must match the order in which they are written. Note that the output and input parameters passed to these functions directly reference the Socket or ByteArray object on which you called writeObject.
This makes it easy to make mistakes such as reading data that does not belong to the object. In the above example, the length of the serialized byte array that is part of the object had to be written by the writeExternal function so that the readExternal code would know how many bytes to put into the byte array on deserialization. (You can look at the AMF specification for reasonable solutions to other challenges of serialization.).
Attention, Internet Explorer User Announcement: Jive has discontinued support for Internet Explorer 7 and below. In order to provide the best platform for continued innovation, Jive no longer supports Internet Explorer 7. Jive will not function with this version of Internet Explorer. Please consider upgrading to a more recent version of Internet Explorer, or trying another browser such as Firefox, Safari, or Google Chrome.
(Please remember to honor your company's IT policies before installing new software!).