buffSize(Number) |
||
isServer(Bool) |
||
status(Number) |
startServerSocket(ip,port) |
|
|
startClientSocket(ip,port) |
|
|
closeSocket() |
||
disconnect(key) |
|
|
sendToServer(type,tokey,args,msg) |
|
|
sendToClient(tokey,type,fkey,args,msg) |
|
|
sendToAllClient(type,fkey,args,msg) |
|
|
getClientsKeys() |
||
setCallMessage(func) |
ISocket.GetLocalIpAddress() |
|
|
ISocket.EnumComputers(port,func) |
|
|
ISocket.AddRuleForInbound(name,msg,filename) |
|
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); } } |