ISocket 通讯(仅Window端可用)


属性

属性 说明 备注

buffSize(Number)

动画是否循环播放 Whether Animation loop or not

isServer(Bool)

动画绑定的精灵对象 The sprite binding on animation

status(Number)

动画x坐标 x-coordinate of animation

函数

函数 说明 备注

startServerSocket(ip,port)

设置动画播放次数 Set frequency of play

times(Number)次数 number of times

times(Number)次数 number of times

startClientSocket(ip,port)

设置当前动画帧 Set current frame

index(Number)动画帧位置 the order of frame

index(Number)动画帧位置 the order of frame

closeSocket()

设置动画坐标 Set coordinates of animation

disconnect(key)

设置动画播放速率 Set the speed of play

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

sendToServer(type,tokey,args,msg)

停止播放动画 Stop playing animation

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

sendToClient(tokey,type,fkey,args,msg)

停止播放动画 Stop playing animation

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

sendToAllClient(type,fkey,args,msg)

为动画重新设置图片 Reset images for animation

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

speed(Number)间隔速度,越大越慢 interval speed, the larger the slower

getClientsKeys()

刷新动画 update animation

刷新动画 update animation

setCallMessage(func)

动画暂停 Animation pause

刷新动画 update animation

刷新动画 update animation

静态函数

静态函数 Static Function说明 Description 备注 Note
ISocket.GetLocalIpAddress()

读取一张工程路径下的位图 Read a bitmap in the project path

返回 Image对象 Return image

本函数在Web读取的路径为 路径+\Res

ISocket.EnumComputers(port,func)

读取一张web端的位图 Read a bitmap on web

path(string) 位图地址 bitmap path

返回 Image对象 Return image

返回 Image对象 Return image

本函数在除Web端意外都与Abitmap相同。

ISocket.AddRuleForInbound(name,msg,filename)

创建位图 Create a bitmap

width(Number)宽度 width of the bitmap

height(Number)高度 height of the bitmap

返回 Image对象 Return image

范例代码

function SText(){

var socket = new ISocket();

socket.setCallMessage("IVal.scene.getMessage")

var sp1 = new ISprite(150,30,IColor.Red());

sp1.drawTextQ("成为服务端",10,10,IColor.Blue(),18);

var sp2 = new ISprite(150,30,IColor.Red());

sp2.drawTextQ("成为客户端",10,10,IColor.Blue(),18);

sp2.y = 40; var sp3 = new ISprite(150,30,IColor.Red());

sp3.drawTextQ("发送消息",10,10,IColor.Blue(),18);

sp3.y = 80;

this.update = function(){

if(sp1.isSelected() && IInput.up){

IInput.up = false;

gameInput("创建服务端","请输入IP","127.0.0.1",function(text){

socket.startServerSocket(text,31882);

});

}

if(sp2.isSelected() && IInput.up){

IInput.up = false;

gameInput("连接服务端","请输入IP","127.0.0.1",function(text){

socket.startClientSocket(text,31882);

});

} if(sp3.isSelected() && IInput.up){

IInput.up = false;

gameInput("发送消息","发送内容","",function(text){

socket.sendToServer(0,"","测试",text);

});

} }

this.getMessage = function( type,  fkey,  args1,  args2){

if(type == 0){//系统消息

if(args1 == "S_NC"){//有新用户连接至socket,系统保留

log("client key:" + args2)

}else if(args1 == "S_K"){ //当前客户端已连接至服务端,系统保留

log("self key:" + args2);

}else if(args1 == "S_DC"){//房间内有人掉线了,系统保留

} }

log(type + "," + fkey + "," + args1 + "," + args2); } }