日立扶梯项目功能测试
作者:网络转载 发布时间:[ 2012/9/7 11:53:27 ] 推荐标签:
Socket三次握手例子:
package
{
import flash.display.Sprite;
import flash.events.ProgressEvent;
import flash.net.Socket;
import flash.utils.ByteArray;
/**
*
* 三次握手连接socket
* 来源socket编程
*/
public class SocketHandshake extends Sprite
{
public const DETERMINE_VERSION:int = 0;
public const RECEIVE_CHALLENGE:int = 1;
public const NORMAL:int = 2;
private var stateMap:Object;
private var currentState:int;
private var socket:Socket;
public function SocketHandshake( )
{
stateMap = new Object( );
stateMap[DETERMINE_VERSION] = readVersion;
stateMap[RECEIVE_CHALLENGE] = readChallenge;
stateMap[NORMAL] = readNormalProtocol;
currentState = DETERMINE_VERSION;
socket = new Socket( );
socket.addEventListener( ProgressEvent.SOCKET_DATA, onSocketData );
socket.connect( "localhost", 9000 );
trace(currentState);
}
private function onSocketData( event:ProgressEvent ):void
{
trace(currentState);
var processFunc:Function = stateMap[currentState];
processFunc( );
}
private function readVersion( ):void
{
try
{
var version:int = socket.readInt();
trace(version);
}
catch (error:Error)
{
trace("error:"+error);
}
currentState = RECEIVE_CHALLENGE;
socket.writeInt( version );
socket.flush( );
}
private function readChallenge( ):void
{
var bytes:ByteArray = new ByteArray( );
socket.readBytes( bytes, 0, 8 );
currentState = NORMAL;
socket.writeBytes( bytes );
socket.flush( );
}
private function readNormalProtocol( ):void
{
}
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11