用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考
主页  |  隐藏包列表和类列表 |   |   |  新增内容  |  索引  |  附录  |  为什么显示为英语?
过滤条件: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隐藏过滤条件
flash.net 

Socket  - AS3

x

顶级
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

语言元素

全局常量
全局函数
运算符
语句、关键字和指令
特殊类型

附录

新增内容
编译器错误
编译器警告
运行时错误
迁移到 ActionScript 3
支持的字符集
仅适用于 MXML 的标签
Motion XML 元素
Timed Text 标记
不推荐使用的元素的列表
AccessibilityImplementation 常量
如何使用 ActionScript 示例
法律声明
flash.net
public class Socket
继承Socket Inheritance EventDispatcher Inheritance Object
实现 IDataInput, IDataOutput
子类 SecureSocket

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

Socket 类启用代码以建立传输控制协议 (TCP) 套接字连接,用于发送和接收二进制数据。

Socket 类与使用二进制协议的服务器一起使用时非常有用。

要使用 Socket 类的方法,请先使用构造函数 new Socket 创建一个 Socket 对象。

套接字以异步方式传输和接收数据。

在某些操作系统上,在执行帧之间会自动调用 flush(),但在其他操作系统(如 Windows)上,除非明确调用 flush(),否则不会发送数据。要确保应用程序在所有操作系统上都具有可靠的功能,在将每条消息(或相关数据组)写入套接字之后,最好调用 flush() 方法。

在 Adobe AIR 中,当侦听 ServerSocket 接收到来自外部进程的连接时,也会创建 Socket 对象。Socket 对象表示在 ServerSocketConnectEvent 中调度了该连接。您的应用程序负责保持对此 Socket 对象的引用。如果不这样做,则 Socket 对象符合垃圾回收的条件,可能会在运行时损坏,但不会发出警告。

在只能与本地文件系统内容交互的安全沙箱中运行的 SWF 内容无法使用套接字。

目标主机上的套接字策略文件 指定 SWF 文件可从中建立套接字连接的主机,并指定可以建立这些连接的端口。在新近发布的几个版本的 Flash Player 中,有关套接字策略文件的安全要求变得更加严格。对于所有版本的 Flash Player,Adobe 建议使用套接字策略文件;在某些情况下,必须使用套接字策略文件。因此,如果使用的是 Socket 对象,必要时请确保目标主机提供了套接字策略文件。

以下列表汇总了各个版本的 Flash Player 中针对套接字策略文件的要求:

  • 在 Flash Player 9.0.124.0 和更高版本中,任何套接字连接都要求套接字策略文件。也就是说,无论连接到哪一个端口(即使连接到提供 SWF 文件的同一主机上的端口),目标主机上都需要套接字策略文件。
  • 在 Flash Player 9.0.115.0 版及更低版本中,如果要连接到小于 1024 的端口号或连接到除提供 SWF 文件的主机之外的主机,则目标主机上必须具有套接字策略文件。
  • 在 Flash Player 9.0.115.0 中,尽管套接字策略文件不是必需的,但如果目标主机未提供套接字策略文件,那么当使用 Flash Debug Player 时,也会显示警告。
  • 在 AIR 中,在应用程序安全沙箱中运行的内容不要求套接字策略文件。在 AIR 应用程序安全沙箱之外运行的内容建立的任何套接字连接均要求套接字策略文件。

有关安全性的详细信息,请参阅 Flash Player 开发人员中心主题:安全性

查看示例

相关 API 元素



公共属性
 属性由以下参数定义
  bytesAvailable : uint
[只读] 输入缓冲区中可读取的数据的字节数。
Socket
  bytesPending : uint
[只读] 表示写缓冲区中剩余的字节数。
Socket
  connected : Boolean
[只读] 表示此 Socket 对象目前是否已连接。
Socket
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  endian : String
表示数据的字节顺序。
Socket
      localAddress : String
[只读] 本地计算机上此套接字绑定到的 IP 地址。
Socket
      localPort : int
[只读] 本地计算机上此套接字绑定到的端口。
Socket
  objectEncoding : uint
在写入或读取对象时,控制所使用的 AMF 的版本。
Socket
      remoteAddress : String
[只读] 此套接字连接到的远程计算机的 IP 地址。
Socket
      remotePort : int
[只读] 此套接字连接到的远程计算机的端口。
Socket
  timeout : uint
表示建立连接时需等待的毫秒数。
Socket
公共方法
 方法由以下参数定义
  
Socket(host:String = null, port:int = 0)
创建新的 Socket 对象。
Socket
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
关闭套接字。
Socket
  
connect(host:String, port:int):void
将套接字连接到指定的主机和端口。
Socket
 Inherited
将事件调度到事件流中。
EventDispatcher
  
对套接字输出缓冲区中积累的所有数据进行刷新。
Socket
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
  
从套接字读取一个布尔值。
Socket
  
从套接字读取一个带符号字节。
Socket
  
readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
从套接字读取 length 参数指定的数据字节数。
Socket
  
从套接字读取一个 IEEE 754 双精度浮点数。
Socket
  
从套接字读取一个 IEEE 754 单精度浮点数。
Socket
  
从套接字读取一个带符号的 32 位整数。
Socket
  
readMultiByte(length:uint, charSet:String):String
使用指定的字符集,从该字节流读取一个多字节字符串。
Socket
  
从以 AMF 序列化格式编码的套接字读取一个对象。
Socket
  
从套接字读取一个带符号的 16 位整数。
Socket
  
从套接字读取一个无符号字节。
Socket
  
从套接字读取一个无符号的 32 位整数。
Socket
  
从套接字读取一个无符号的 16 位整数。
Socket
  
从套接字读取一个 UTF-8 字符串。
Socket
  
从套接字读取 length 参数所指定的 UTF-8 数据的字节数,并返回一个字符串。
Socket
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。
EventDispatcher
  
将一个布尔值写入套接字。
Socket
  
将一个字节写入套接字。
Socket
  
writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
从指定的字节数组写入一系列字节。
Socket
  
将一个 IEEE 754 双精度浮点数写入套接字。
Socket
  
将一个 IEEE 754 单精度浮点数写入套接字。
Socket
  
将一个带符号的 32 位整数写入套接字。
Socket
  
使用指定的字符集,从该字节流写入一个多字节字符串。
Socket
  
以 AMF 序列化格式将一个对象写入套接字。
Socket
  
将一个 16 位整数写入套接字。
Socket
  
将一个无符号的 32 位整数写入套接字。
Socket
  
将以下数据写入套接字:一个无符号 16 位整数,它表示了指定 UTF-8 字符串的长度(以字节为单位),后面跟随字符串本身。
Socket
  
将一个 UTF-8 字符串写入套接字。
Socket
事件
 事件 摘要 由以下参数定义
 Inherited[广播事件] Flash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时将调度此事件。EventDispatcher
  在服务器关闭套接字连接时调度。Socket
  在建立网络连接后调度。Socket
 Inherited[广播事件] Flash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时将调度此事件。EventDispatcher
  在出现输入/输出错误并导致发送或加载操作失败时调度。Socket
  当套接字将其写缓冲区的数据移到网络传输层时调度Socket
  若对 Socket.connect() 的调用尝试连接到调用方的安全沙箱禁止的服务器或低于 1024 的端口,且不存在允许进行此类连接的套接字策略文件,则进行调度。Socket
  在套接字接收到数据后调度。Socket
属性详细信息

bytesAvailable

属性
bytesAvailable:uint  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

输入缓冲区中可读取的数据的字节数。

代码必须访问 bytesAvailable 以确保在尝试使用其中一种 read 方法读取数据之前,有足够的数据可用。



实现
    public function get bytesAvailable():uint

bytesPending

属性 
bytesPending:uint  [只读]

语言版本: ActionScript 3.0
运行时版本: Flash Player 11, AIR 3.0

表示写缓冲区中剩余的字节数。

此属性与 OutputProgressEvent 一起使用。每当将数据从写缓冲区写到网络时,便会引发 OutputProgressEvent。在该事件处理函数中,您可以检查 bytesPending,查看还有多少数据仍留在缓冲区中等待写入。当 bytesPending 返回 0 时,说明所有数据已从写缓冲区传送到网络,可以安全执行诸如删除事件处理函数、清空套接字引用、启动队列中的下一个上载等操作。



实现
    public function get bytesPending():uint

相关 API 元素

connected

属性 
connected:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

表示此 Socket 对象目前是否已连接。如果该套接字当前已连接,则对此属性的调用将返回值 true,否则将返回 false



实现
    public function get connected():Boolean

endian

属性 
endian:String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

表示数据的字节顺序。可能的值为来自 flash.utils.Endian 类的常量、Endian.BIG_ENDIANEndian.LITTLE_ENDIAN

默认值为 Endian.BIG_ENDIAN。



实现
    public function get endian():String
    public function set endian(value:String):void

相关 API 元素

    

localAddress

属性 
localAddress:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

本地计算机上此套接字绑定到的 IP 地址。



实现
    public function get localAddress():String

相关 API 元素

    

localPort

属性 
localPort:int  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

本地计算机上此套接字绑定到的端口。



实现
    public function get localPort():int

相关 API 元素

objectEncoding

属性 
objectEncoding:uint

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

在写入或读取对象时,控制所使用的 AMF 的版本。



实现
    public function get objectEncoding():uint
    public function set objectEncoding(value:uint):void

相关 API 元素

    

remoteAddress

属性 
remoteAddress:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

此套接字连接到的远程计算机的 IP 地址。

您可以使用此属性确定 ServerSocketConnectEvent 中由 ServerSocket 对象调度的客户端套接字的 IP 地址。如果需要,使用 DNSResolver 类将 IP 地址转换为域名。



实现
    public function get remoteAddress():String

相关 API 元素

    

remotePort

属性 
remotePort:int  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 2

此套接字连接到的远程计算机的端口。

您可以使用此属性确定 ServerSocketConnectEvent 中由 ServerSocket 对象调度的客户端套接字的端口号。



实现
    public function get remotePort():int

相关 API 元素

timeout

属性 
timeout:uint

语言版本: ActionScript 3.0
运行时版本: Flash Player 10, AIR 1.5, Flash Lite 4

表示建立连接时需等待的毫秒数。

如果在指定时间内未成功建立连接,则连接失败。默认值是 20,000(20 秒)。



实现
    public function get timeout():uint
    public function set timeout(value:uint):void
构造函数详细信息

Socket

()构造函数
public function Socket(host:String = null, port:int = 0)

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

创建新的 Socket 对象。若未指定参数,将创建一个最初处于断开状态的套接字。若指定了参数,则尝试连接到指定的主机和端口。

注意:强烈建议使用不带参数的构造函数形式,并添加任意事件侦听器,然后使用 hostport 参数调用 connect 方法。此序列将确保所有事件侦听器工作正常。

参数
host:String (default = null) — 完全限定的 DNS 域名或 IP 地址。IPv4 地址使用十进制点符号指定,如 192.0.2.0。在 Flash Player 9.0.115.0 和 AIR 1.0 和更高版本中,可以使用十六进制冒号符号指定 IPv6 地址,如 2001:db8:ccc3:ffff:0:444d:555e:666f。也可指定 null 以连接到 SWF 文件所在的主机服务器。如果发出此调用的 SWF 文件正在 Web 浏览器中运行,则 host 必须与该 SWF 文件位于同一域中。
 
port:int (default = 0) — 用于建立连接的目标主机上的 TCP 端口号。在 Flash Player 9.0.124.0 及更高版本中,目标主机必须提供套接字策略文件,以指定允许建立从提供 SWF 文件的主机到指定端口的套接字连接。在早期版本的 Flash Player 中,仅在要连接到小于 1024 的端口号或连接到除提供 SWF 文件的主机之外的主机时,才需要使用套接字策略文件。

事件
connect:Event — 在建立网络连接后调度。
 
ioError:IOErrorEvent — 在出现输入/输出错误并由此导致连接失败时调度。
 
securityError:SecurityErrorEvent如果对 Socket.connect() 的调用试图连接的服务器不提供套接字策略文件,或者服务器的策略文件未授予对指定端口的调用主机访问权限,则调度此事件。有关策略文件的详细信息,请参阅《ActionScript 3.0 开发人员指南》中的“网站控制(策略文件)”和 Flash Player 开发人员中心主题安全性

引发
SecurityError — SWF 内容中发生此错误的原因如下:
  • 与本地文件系统内容交互的文件无法与 Internet 进行通信。您可以通过将此 SWF 文件重新分类为只能与远程内容交互或受信任来解决此问题。此限制不是为应用程序安全沙箱中的 AIR 应用程序内容设置的。
  • 您不能指定高于 65535 的套接字端口。
方法详细信息

close

()方法
public function close():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

关闭套接字。在调用 close() 方法之后,将无法读取或写入任何数据。

仅在服务器关闭连接时调度 close 事件;在调用 close() 方法时不调度该事件。

可通过再次对 Socket 对象调用 connect() 方法来重复使用该对象。


引发
IOError — 无法关闭套接字,或者套接字未打开。

connect

()方法 
public function connect(host:String, port:int):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将套接字连接到指定的主机和端口。

如果连接立即失败,则调度一个事件或引发一个异常。如果指定了主机,则调度一个错误事件;如果未指定主机,则引发异常。另外,连接的状态由事件来报告。如果已连接上套接字,则现有的连接将首先关闭。

参数

host:String — 要连接到的主机的名称或 IP 地址。如果未指定主机,则要连接的主机为执行调用的 文件所在的主机。如果不指定主机,请使用事件侦听器来确定连接是否成功。
 
port:int — 要连接到的端口号。


事件
connect:Event — 在建立网络连接后调度。
 
ioError:IOErrorEvent — 在指定了主机但出现输入/输出错误并由此导致连接失败时调度。
 
securityError:SecurityErrorEvent — 如果对 Socket.connect() 的调用试图与未提供套接字策略文件的服务器进行连接,或者试图与其策略文件未授予执行调用的主机对指定端口的访问权的服务器进行连接,则调度此事件。有关策略文件的详细信息,请参阅《ActionScript 3.0 开发人员指南》中的“网站控制(策略文件)”和 Flash Player 开发人员中心主题安全性

引发
IOError — 未指定任何主机,而且连接失败。
 
SecurityError — SWF 内容中发生此错误的原因如下:
  • 本地不受信任的 SWF 文件可能无法与 Internet 进行通信。可以通过将此文件重新分类为只能与远程内容交互的文件或受信任的文件来突破此限制。
  • 您不能指定高于 65535 的套接字端口。
  • 在包含 SWF 内容的 HTML 页中,objectembed 标签的 allowNetworking 参数设置为 "none"

flush

()方法 
public function flush():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

对套接字输出缓冲区中积累的所有数据进行刷新。

在某些操作系统上,在执行帧之间会自动调用 flush(),但在其他操作系统(如 Windows)上,除非明确调用 flush(),否则不会发送数据。要确保应用程序在所有操作系统上都具有可靠的功能,在将每条消息(或相关数据组)写入套接字之后,最好调用 flush() 方法。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readBoolean

()方法 
public function readBoolean():Boolean

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个布尔值。在读取一个字节之后,如果该字节不为零,则该方法返回 true,否则返回 false

返回
Boolean — 如果所读取的字节不为零,则值为 true,否则为 false

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readByte

()方法 
public function readByte():int

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个带符号字节。

返回
int — 从 -128 至 127 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readBytes

()方法 
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取 length 参数指定的数据字节数。从 offset 所表示的位置开始,将这些字节读入指定的字节数组。

参数

bytes:ByteArray — 要将数据读入的 ByteArray 对象。
 
offset:uint (default = 0) — 数据读取的偏移量应从该字节数组中开始。
 
length:uint (default = 0) — 要读取的字节数。默认值 0 导致读取所有可用的数据。


引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readDouble

()方法 
public function readDouble():Number

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个 IEEE 754 双精度浮点数。

返回
Number — 一个 IEEE 754 双精度浮点数。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readFloat

()方法 
public function readFloat():Number

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个 IEEE 754 单精度浮点数。

返回
Number — 一个 IEEE 754 单精度浮点数。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readInt

()方法 
public function readInt():int

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个带符号的 32 位整数。

返回
int — 从 -2147483648 至 2147483647 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readMultiByte

()方法 
public function readMultiByte(length:uint, charSet:String):String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

使用指定的字符集,从该字节流读取一个多字节字符串。

参数

length:uint — 要从字节流中读取的字节数。
 
charSet:String — 表示用于解释字节的字符集的字符串。可能的字符集字符串包括 "shift_jis""CN-GB""iso-8859-1"。有关完整列表,请参阅支持的字符集

注意:如果当前系统无法识别 charSet 参数的值,则应用程序将使用系统的默认代码页作为字符集。例如,charSet 参数的值(如在使用 01 而不是 1myTest.readMultiByte(22, "iso-8859-01") 中)可能在您的开发计算机上起作用,但在其他计算机上可能不起作用。在其它计算机上,应用程序将使用系统的默认代码页。

返回
String — UTF-8 编码的字符串。

引发
EOFError — 可读取的数据不足。

readObject

()方法 
public function readObject():*

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从以 AMF 序列化格式编码的套接字读取一个对象。

返回
* — 反序列化的对象

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

readShort

()方法 
public function readShort():int

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个带符号的 16 位整数。

返回
int — 从 -32768 至 32767 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readUnsignedByte

()方法 
public function readUnsignedByte():uint

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个无符号字节。

返回
uint — 从 0 至 255 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readUnsignedInt

()方法 
public function readUnsignedInt():uint

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个无符号的 32 位整数。

返回
uint — 从 0 至 4294967295 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readUnsignedShort

()方法 
public function readUnsignedShort():uint

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个无符号的 16 位整数。

返回
uint — 从 0 至 65535 的值。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readUTF

()方法 
public function readUTF():String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取一个 UTF-8 字符串。假定该字符串的前缀是表示字符串长度(以字节为单位)的无符号短整数。

返回
String — UTF-8 字符串。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

readUTFBytes

()方法 
public function readUTFBytes(length:uint):String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从套接字读取 length 参数所指定的 UTF-8 数据的字节数,并返回一个字符串。

参数

length:uint — 要读取的字节数。

返回
String — UTF-8 字符串。

引发
EOFError — 可读取的数据不足。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

writeBoolean

()方法 
public function writeBoolean(value:Boolean):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个布尔值写入套接字。此方法写入了一个字节,其值为 1 (true ) 或 0 ( false)。

参数

value:Boolean — 要写入套接字的值:1 (true ) 或 0 ( false)。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeByte

()方法 
public function writeByte(value:int):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个字节写入套接字。

参数

value:int — 要写入套接字的值。使用了该值的低 8 位;忽略了高 24 位。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeBytes

()方法 
public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

从指定的字节数组写入一系列字节。写入操作从 offset 指定的位置开始。

如果省略了 length 参数,则默认长度 0 将导致该方法从 offset 开始写入整个缓冲区。

如果还省略了 offset 参数,则写入整个缓冲区。

参数

bytes:ByteArray — 要从中读取数据的 ByteArray 对象。
 
offset:uint (default = 0)bytes ByteArray 对象中从零开始的偏移量,应由此开始执行数据写入。
 
length:uint (default = 0) — 要写入的字节数。默认值 0 导致从 offset 参数指定的值开始写入整个缓冲区。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。
 
RangeError — 如果 offset 大于 bytes 指定的 ByteArray 长度;如果指定的要根据 offset 加上 length 写入的数据量超出可用数据。

相关 API 元素

writeDouble

()方法 
public function writeDouble(value:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个 IEEE 754 双精度浮点数写入套接字。

参数

value:Number — 要写入套接字的值。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeFloat

()方法 
public function writeFloat(value:Number):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个 IEEE 754 单精度浮点数写入套接字。

参数

value:Number — 要写入套接字的值。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeInt

()方法 
public function writeInt(value:int):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个带符号的 32 位整数写入套接字。

参数

value:int — 要写入套接字的值。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeMultiByte

()方法 
public function writeMultiByte(value:String, charSet:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

使用指定的字符集,从该字节流写入一个多字节字符串。

参数

value:String — 要写入的字符串值。
 
charSet:String — 表示用于解释字节的字符集的字符串。可能的字符集字符串包括 "shift_jis""CN-GB""iso-8859-1"。有关完整列表,请参阅支持的字符集

相关 API 元素

writeObject

()方法 
public function writeObject(object:*):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

以 AMF 序列化格式将一个对象写入套接字。

参数

object:* — 要进行序列化处理的对象。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeShort

()方法 
public function writeShort(value:int):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个 16 位整数写入套接字。写入的字节如下:

(v >> 8) & 0xff v & 0xff

使用了该参数的低 16 位;忽略了高 16 位。

参数

value:int — 要写入套接字的值。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeUnsignedInt

()方法 
public function writeUnsignedInt(value:uint):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个无符号的 32 位整数写入套接字。

参数

value:uint — 要写入套接字的值。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeUTF

()方法 
public function writeUTF(value:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将以下数据写入套接字:一个无符号 16 位整数,它表示了指定 UTF-8 字符串的长度(以字节为单位),后面跟随字符串本身。

写入字符串之前,该方法会计算表示该字符串的所有字符所需的字节数。

参数

value:String — 要写入套接字的字符串。


引发
RangeError — 长度大于 65535。
 
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

writeUTFBytes

()方法 
public function writeUTFBytes(value:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

将一个 UTF-8 字符串写入套接字。

参数

value:String — 要写入套接字的字符串。


引发
IOError — 套接字上发生 I/O 错误,或者套接字未打开。

相关 API 元素

事件详细信息

close

事件
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.CLOSE

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

在服务器关闭套接字连接时调度。

仅在服务器关闭连接时调度 close 事件;在调用 Socket.close() 方法时不调度该事件。

Event.CLOSE 常量定义 close 事件对象的 type 属性的值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已关闭其连接的对象。

connect

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.CONNECT

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

在建立网络连接后调度。

Event.CONNECT 常量定义 connect 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已建立网络连接的 Socket 或 XMLSocket 对象。

ioError

事件  
事件对象类型: flash.events.IOErrorEvent
属性 IOErrorEvent.type = flash.events.IOErrorEvent.IO_ERROR

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

在出现输入/输出错误并导致发送或加载操作失败时调度。

定义 ioError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
errorID与特定错误关联的引用编号(仅限 AIR)。
target发生输入/输出错误的网络对象。
text要显示为错误消息的文本。

outputProgress

事件  
事件对象类型: flash.events.OutputProgressEvent

当套接字将其写缓冲区的数据移到网络传输层时调度

securityError

事件  
事件对象类型: flash.events.SecurityErrorEvent
属性 SecurityErrorEvent.type = flash.events.SecurityErrorEvent.SECURITY_ERROR

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

若对 Socket.connect() 的调用尝试连接到调用方的安全沙箱禁止的服务器或低于 1024 的端口,且不存在允许进行此类连接的套接字策略文件,则进行调度。

注意:在 AIR 应用程序中,不需要套接字策略文件即允许在应用程序安全沙箱中运行的内容连接到任何服务器和端口号。

SecurityErrorEvent.SECURITY_ERROR 常量定义 securityError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target报告安全错误的网络对象。
text要显示为错误消息的文本。

相关 API 元素

socketData

事件  
事件对象类型: flash.events.ProgressEvent
属性 ProgressEvent.type = flash.events.ProgressEvent.SOCKET_DATA

语言版本: ActionScript 3.0
运行时版本: AIR 1.0, Flash Player 9, Flash Lite 4

在套接字接收到数据后调度。

套接字接收的数据在被读取之前一直保持在套接字中。在此事件的处理期间,您不必读取所有可用的数据。

socketData 类型的事件不使用 ProgressEvent.bytesTotal 属性。

定义 socketData 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在处理此事件的对象。
bytesLoaded在侦听器处理事件时加载的项数或字节数。
bytesTotal0;socketData 事件对象不使用此属性。
target报告进度的套接字。
SocketExample.as

下例对套接字执行读写操作,并输出在套接字事件期间传输的信息。该示例的要点遵循:
  1. 该构造函数创建 CustomSocket 实例,名为 socket,并将主机名 localhost 和端口 80 作为参数传递。由于 CustomSocket 扩展了 Socket,因此在调用 super() 时将调用 Socket 的构造函数。
  2. 然后,该示例调用了 configureListeners() 方法,该方法可为 Socket 事件添加侦听器。
  3. 最后,调用套接字 connect() 方法,其中使用 localhost 作为主机名并使用 80 作为端口号。

注意:为了运行该示例,您需要一台与 SWF 位于同一个域(在本例中为 localhost)服务器并侦听端口 80。

package {
    import flash.display.Sprite;

    public class SocketExample extends Sprite {
        private var socket:CustomSocket;
        
        public function SocketExample() {
            socket = new CustomSocket("localhost", 80);
        }
    }
}

import flash.errors.*;
import flash.events.*;
import flash.net.Socket;

class CustomSocket extends Socket {
    private var response:String;

    public function CustomSocket(host:String = null, port:uint = 0) {
        super();
        configureListeners();
        if (host && port)  {
            super.connect(host, port);
        }
    }

    private function configureListeners():void {
        addEventListener(Event.CLOSE, closeHandler);
        addEventListener(Event.CONNECT, connectHandler);
        addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
    }

    private function writeln(str:String):void {
        str += "\n";
        try {
            writeUTFBytes(str);
        }
        catch(e:IOError) {
            trace(e);
        }
    }

    private function sendRequest():void {
        trace("sendRequest");
        response = "";
        writeln("GET /");
        flush();
    }

    private function readResponse():void {
        var str:String = readUTFBytes(bytesAvailable);
        response += str;
    }

    private function closeHandler(event:Event):void {
        trace("closeHandler: " + event);
        trace(response.toString());
    }

    private function connectHandler(event:Event):void {
        trace("connectHandler: " + event);
        sendRequest();
    }

    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("ioErrorHandler: " + event);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

    private function socketDataHandler(event:ProgressEvent):void {
        trace("socketDataHandler: " + event);
        readResponse();
    }
}




[ X ]为什么显示为英语?
《ActionScript 3.0 参考》中的内容以英语显示

《ActionScript 3.0 参考》中的部分内容未翻译成所有语言。当某个语言元素未翻译时,将显示为英语。例如,ga.controls.HelpBox 类未翻译成任何语言。因此在简体中文版的参考中,ga.controls.HelpBox 类显示为英语。