global g_multiUserInstance
on preparemovie
if g_multiUserInstance<>0 then g_multiUserInstance = 0
-- 1.创建新的MultiUser实例
g_multiUserInstance = new Xtra("MultiUser")
if g_multiUserInstance<>0 then
-- 2.获取本机IP
localip = g_multiUserInstance.getNetAddressCookie(0)
-- 3.设置网络消息的处理回调函数
-- param1, 回调
-- param2, 回调所在的脚本对象,它可以是一个script member的名字,也可以是
-- the name of a variable containing a behavior instance,
-- a parent script,
-- or a simple Lingo value to be passed to global scripts.
-- param3, string,subject.过滤设置,只处理subject为该值的消息
-- param4, string, senderid,过滤设置,只处理来自该movie的消息
-- param5, bool, 是否将消息内容作为回调的参数,
-- false,handler形如本例,需要手动getNetMessage()获得newmessage
-- 为true时,handler的形式为 on defaultHandler _newmessage
-- 注, 如果handler是behavior或parent, _newmessage位于me后
errcode = g_multiUserInstance.setNetMessageHandler(#getMessageHandler, script"MovieScript")
-- 4.连接到服务器
-- connectToNetServer的格式有三种,示例使用形式最简单的(string LocalID, string password, string serverIP, integer port, movidIDstring)
errcode = g_multiUserInstance.connectToNetServer ( "Client1", "pwd", "192.168.0.54", 1626, "TestMUS" )
-- 1)connectToNetServer(userNameString, passwordString, serverIDString, portNumber, movieIDString {, #mode} {, encryptionKey})
-- 2)connectToNetServer(serverIDString, portNumber, [#userID: userNameString, #password: passwordString, #movieID: movieIDString] {, #mode} {, encryptionKey})
-- 3)connectToNetServer([#logonInfo: [#userID: userNameString, #password: passwordString, #movieID: movieIDString], #remoteAddress: serverIDString {, #remoteTCPPort: serverPortNumber} {, #localAddress: clientIPAddress} {, #encryptionKey: encryptionKeyString}])
end if
end
on startmovie
end
on mouseUp
sendMessage()
end
on stopmovie
g_multiUserInstance = 0
end
-- 消息处理回调函数
on getMessageHandler
newMessage = g_multiUserInstance.getNetMessage()
put newMessage
end
on sendMessage
on preparemovie
if g_multiUserInstance<>0 then g_multiUserInstance = 0
-- 1.创建新的MultiUser实例
g_multiUserInstance = new Xtra("MultiUser")
if g_multiUserInstance<>0 then
-- 2.获取本机IP
localip = g_multiUserInstance.getNetAddressCookie(0)
-- 3.设置网络消息的处理回调函数
-- param1, 回调
-- param2, 回调所在的脚本对象,它可以是一个script member的名字,也可以是
-- the name of a variable containing a behavior instance,
-- a parent script,
-- or a simple Lingo value to be passed to global scripts.
-- param3, string,subject.过滤设置,只处理subject为该值的消息
-- param4, string, senderid,过滤设置,只处理来自该movie的消息
-- param5, bool, 是否将消息内容作为回调的参数,
-- false,handler形如本例,需要手动getNetMessage()获得newmessage
-- 为true时,handler的形式为 on defaultHandler _newmessage
-- 注, 如果handler是behavior或parent, _newmessage位于me后
errcode = g_multiUserInstance.setNetMessageHandler(#getMessageHandler, script"MovieScript")
-- 4.连接到服务器
-- connectToNetServer的格式有三种,示例使用形式最简单的(string LocalID, string password, string serverIP, integer port, movidIDstring)
errcode = g_multiUserInstance.connectToNetServer ( "Client1", "pwd", "192.168.0.54", 1626, "TestMUS" )
-- 1)connectToNetServer(userNameString, passwordString, serverIDString, portNumber, movieIDString {, #mode} {, encryptionKey})
-- 2)connectToNetServer(serverIDString, portNumber, [#userID: userNameString, #password: passwordString, #movieID: movieIDString] {, #mode} {, encryptionKey})
-- 3)connectToNetServer([#logonInfo: [#userID: userNameString, #password: passwordString, #movieID: movieIDString], #remoteAddress: serverIDString {, #remoteTCPPort: serverPortNumber} {, #localAddress: clientIPAddress} {, #encryptionKey: encryptionKeyString}])
end if
end
on startmovie
end
on mouseUp
sendMessage()
end
on stopmovie
g_multiUserInstance = 0
end
-- 消息处理回调函数
on getMessageHandler
newMessage = g_multiUserInstance.getNetMessage()
put newMessage
end
on sendMessage
-- param1为@AllUsers,发送至所有客户端;param1形如system.server.getVersion,是调用服务器方法
errcode = g_multiUserInstance.sendNetMessage( "Client1", "TEST", "I'm here")
end
on exitFrame
go to the frame
end