Flex 与Python之间Socket通讯
来源:互联网 发布:桌面倒计时软件下载 编辑:程序博客网 时间:2024/06/11 01:54
查阅Adobe提供的API文档可以了解到,XMLSocket提供了四个公开方法:
1、XMLSocket(host:String=null,port:int=0)--创建一个新的XMLSocket对象。
2、close():void--关闭一个XMLSocket。
3、connect(host:String,port:int):void--连接到指定的TCP端口。
4、send(object:*):void--将数据发送到连接服务端。
客户端Flex代码:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()"> <mx:Script> <![CDATA[ private var custSocket:Socket; [Bindable] private var response:String = ""; private function init():void { custSocket = new Socket("localhost", 21567); configureListeners(); } private function onClick(evt:Event):void { sendRequest(); } private function configureListeners():void { custSocket.addEventListener(Event.CLOSE, closeHandler); custSocket.addEventListener(Event.CONNECT, connectHandler); custSocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); custSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); custSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); } private function writeln(str:String):void { str += "\n"; try { custSocket.writeUTFBytes(str); } catch(e:IOError) { trace(e); } } private function sendRequest():void { trace("sendRequest"); writeln(inTxt.text); custSocket.flush(); } private function readResponse():void { var str:String = custSocket.readUTFBytes(custSocket.bytesAvailable); response += str; } private function closeHandler(event:Event):void { trace("closeHandler: " + event); trace(response.toString()); } private function connectHandler(event:Event):void { trace("connectHandler: " + event); } 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(); } ]]> </mx:Script> <mx:TextArea text="{response}" id="outTxt" height="126" width="283" fontSize="12"/> <mx:HBox verticalAlign="bottom" width="282" height="40"> <mx:TextArea id="inTxt" width="100%" height="100%" fontSize="12"/> <mx:Button label="发送" fontSize="12" click="onClick(event)"/> </mx:HBox> </mx:Application>
服务器端Python代码:
#!/usr/bin/env python #coding=utf-8 from socket import * from time import ctime HOST=‘localhost’ PORT=21567 BUFSIZ=4096 ADDR=(HOST, PORT) tcpSerSock = socket(AF_INET, SOCK_STREAM) tcpSerSock.bind(ADDR) tcpSerSock.listen(5) while True: print ‘waiting for connection…’ tcpCliSock, addr = tcpSerSock.accept() print ‘…connected from:’, addr while True: data = tcpCliSock.recv(BUFSIZ) if not data: break tcpCliSock.send(‘[%s] %s’ % (ctime(), data)) tcpCliSock.close() tcpSerSock.close()
- Flex 与Python之间Socket通讯
- flex通过socket json与后台通讯
- Socket与ServerSocket之间的通讯
- java与c之间的socket通讯
- winform与unity之间的Socket通讯
- Webfocus Flex 之间通讯
- Flex Socket 与 C++ 通讯 --- 安全沙箱问题解决
- Flex Socket 与 C++ 通讯 --- 安全沙箱问题解决
- Flex Socket 与 C++ 通讯 --- 安全沙箱问题解决 (转)
- Flex Socket 与 C++ 通讯 --- 安全沙箱问题解决
- Flex 与 as3.0 SWF 之间的通讯
- flash/flex socket通讯实例
- 利用Socket来实现Erlang与C#之间的通讯
- java与C++之间进行SOCKET通讯要点简要解析
- java与C++之间进行SOCKET通讯要点简要解析
- java与C++之间进行SOCKET通讯要点简要解析
- java与C++之间进行SOCKET通讯要点简要解析
- java与C++之间进行SOCKET通讯要点简要解析
- 开始写博客吧
- 地址
- J2EE技术(三)——JMS
- Inno Setup 官网
- 如何学习iphone游戏开发
- Flex 与Python之间Socket通讯
- Android+Listview+分页+动态加载网络数据
- Oracle创建表空间,用户和授权
- 摘自java解惑 名字重用术语表 有必要好好牢记
- Elsevier投稿实录之signal processing
- java: 一些数字到字符的转换技巧,反射访问类成员数组的方法
- android系统退出代码实现
- overcommit_memory
- (转)Linux——linux学习全攻略