Global g_multiuserinstance
On preparemovie
If G_multiuserinstance <> 0 then g_multiuserinstance = 0
-- 1. Create a New multiuser instance
G_multiuserinstance = new Xtra ("multiuser ")
If G_multiuserinstance <> 0 then
-- 2. Obtain the IP address of the local machine.
Localip = g_multiuserinstance.getnetaddresscookie (0)
-- 3. Set the network message processing callback function
-- Param1, callback
-- Param2: the script object of the callback. It can be the name of a script member or
-- The name of Variable Containing a behavior instance,
-- A parent script,
-- Or a simple lingo value to be passed to global scripts.
-- Param3, String, subject. filter settings. Only messages with this value of subject are processed.
-- Param4, String, senderid, filter settings, only process messages from this movie
-- Param5, bool, whether to use the message content as the callback parameter,
-- False , Handler is like this example, You need to manually getnetmessage () to get newmessage
-- If it is true, handler is in the form of on defaulthandler _ newmessage
-- Note: If handler is behavior or parent, _ newmessage is located after me
Errcode = g_multiuserinstance.setnetmessagehandler (# getmessagehandler, script "moviescript ")
-- 4. Connect to the server
-- Connecttonetserver has three formats. The example uses the simplest format (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
-- Message Processing callback function
On getmessagehandler
Newmessage = g_multiuserinstance.getnetmessage ()
Put newmessage
End
On sendmessage
-- Param1 is @ allusers, which is sent to all clients. param1, such as system. server. getversion, is used to call the server method.
Errcode = g_multiuserinstance.sendnetmessage ("Client1", "test", "I'm here ")
End
On exitframe
Go to the frame
End