从 Actionscript 3 AIR 应用程序连接到 Socket 服务器
我通读了连接到套接字服务器的方法: http ://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html
我编写了一个 AIR 应用程序来连接到 java 服务器代码,但是客户端无法连接。代码中缺少什么?
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" backgroundColor="#D5F8C3">
<fx:Script>
<![CDATA[
import flash.net.XMLSocket;
var socket:XMLSocket;
public function b1_clickHandler(event:MouseEvent):void
{
var socket:XMLSocket;
socket.connect("127.0.0.1",8080);
socket.send("Hello");
//socket.addEventListener(DataEvent.DATA, onData);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button id="b1" x="285" y="162" label="Send Text" width="201" height="105" click="b1_clickHandler(event)"/>
</s:WindowedApplication>
I read through the method to connect to a socket server : http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html
I wrote an AIR application to connect to the java server code, but the client cannot connect. What is missing in the code?
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" backgroundColor="#D5F8C3">
<fx:Script>
<![CDATA[
import flash.net.XMLSocket;
var socket:XMLSocket;
public function b1_clickHandler(event:MouseEvent):void
{
var socket:XMLSocket;
socket.connect("127.0.0.1",8080);
socket.send("Hello");
//socket.addEventListener(DataEvent.DATA, onData);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button id="b1" x="285" y="162" label="Send Text" width="201" height="105" click="b1_clickHandler(event)"/>
</s:WindowedApplication>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在发送数据之前,您必须等待 CONNECTED 事件。另外,请确保您已管理跨域安全性(请参阅:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c60.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7c63)
服务器/客户端代码: Air 2 ServerSocket 跨域问题
You have to wait for CONNECTED event before sending data. Also, be sure you've managed crossdomain security (look at : http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c60.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7c63)
Server/client code exemple : Air 2 ServerSocket Crossdomain problem