[Tutorial] AS 3.0 socket communication, the whole basis of comparison compare, do not go around the

sponsored links
Transfer from http://520pig.blogbus.com/logs/32821429.html

Socket socket connection allows Flash player by specifying the port communicate with the server, but the socket after the data transfer communication is still not close to artificially close. We can use the class to create XML data format flash.net.XMLSocket the socket connection, use the class to create a binary data format flash.net.Socket socket connection, compared with xml data format, binary link is more low-level, but it can connect to almost all socket server-side program. as3.0 socket provided in the link are asynchronous, meaning that you must increase the event listener later in the transfer complete data available

To create a socket communication, we must first establish socket connection, we can use Socket.connect () or XMLSocket.connect () method to establish a connection and connect the event monitor to determine whether the established connection. Connect only two parameters, IP, and port.

Note conditions:

swf and the host must be in the same domain;
Swf on the network can not connect to local server;
Swf can not access any local network resources;
To allow cross-domain access or connection ports lower than 1024, the need for cross-domain policy file.

If you want to visit each other in different domains of the flash can flash.system.Security.loadPolicyFile () to read:
Security.loadPolicyFile ("cross-domain");
cross-domain policy file example:
<? Xml version = "1.0"?>
<! DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domainpolicy.
dtd ">
<allow-access-from domain="*" to-ports="80,110" />
</ Cross-domain-policy>

End connections can be established after the write server, by calling the write method, you can write to write data to the buffer pool, then call the flush () method can be sent to the data, this is for the binary socket, if xml call send () method. as3.0 can define different parameters for different write function: is writeBoolean (), writeByte (), writeBytes (),
writeDouble (), writeFloat (), writeInt (), writeMultiByte (), writeObject (), writeShort (), write-
UnsignedInt (), writeUTF (), and writeUTFBytes (). According to the function name can be aware of the need incoming parameters, here on socket.writeBytes (byteArray, 0, byteArray.length); to explain, because it can pass a data, and develop an array of start and end position for writing. , WriteUTFBytes (): write byte string, writeUTF: numeric string. writeMultiByte () to write to the specified encoding string, socket.writeMultiByte ("example", "unicode");

Once the data would have to send data, so we can ProgressEvent.SOCKET_DATA event handler to read the data, using readBoolean (): Boolean, readByte (): int, readDouble (): Number, readFloat (): Number, readInt (): int, readObject ():*, readShort (): int, readUnsignedByte (): uint, readUnsignedInt (): uint, readUnsignedShort (): uint, readUTF (): String, readBytes () no return parameters, readUTFBytes ( ) return utf8 data. Socket object receives the data is ASCII-encoded text, we can use readUTFBytes () method to reconstruct the string
readUTFBytes () method needs to know how many bytes need to convert, with bytesAvailable property specifies the number of bytes:
var string: String = socket.readUTFBytes (socket.bytesAvailable);

Mentioned above, the socket is in binary transfer mode, if the use xml approach, then the trigger event types, it is DataEvent.DATA trigger event, the event's data property contains the data passed to, if we are to read xml data must first be converted to string in xml format, and then read.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of [Tutorial] AS 3.0 socket communication, the whole basis of comparison compare, do not go around the

  • Spring + Hibernate to use Glassfish Database Connection Pool

    applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " http://www.springframework.org/schema/beans " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " ...

  • Process migration from tomcat to websphere changes

    Process migration from tomcat to websphere changes Because customers use the web application server software used by different what tomcat5, tomcat6, websphere5.1, websphere6.1, weblogic8, and so on, and the software used inconsistent standards, ibm's

  • Ruby on Rails Routing - Simple Examples

    This article contains a list of ruby on rails routing examples. If you find you have any questions please leave a comment. Routes are processed from the top of routes.rb down. If a route is matched it will stop processing the routes.rb file and use that r


    dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • spring struts2.0 hibernate bug killer 1

    exception There is no Action mapped for namespace / and action name checkLogin. - [Unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare (DefaultActionProxy.java: 186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries