Multiuser02-use Xtra to establish a connection with the server

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.