A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Contacts
Logo. www.xtramaina.com  
Home Search E-mail
SocketServerXtra Usage/Client side (sync)

NetCompanionSet xtras for Macromedia Director

Synchronized client component of SocketServerXtra

Synchronized client object is the simple client side for the communication with the Server object over Internet. Similar to multiuser xtra, it can send messages to the server and receive what it replies. 'Synchronized' means that by sending data to the server client is blocked until server replies or connection is dropped.

To create synchronized client object use xtra-level New method:
objClient = xtra("SocketServerXtra").New( #SyncClient )

Use Connect( strServer, nPortNumber, strSenderId ) method to establish connection to the specified server.

Once connection is established you may communicate with the server via Send( valData ) method. Synchronized client is intended for use in remote method call scenario, thus Send( valData ) returns only when the client has received the server's response. This scenario goes well for local area network (LAN) applications, although it may be used in wide area network (WAN) applications too in some cases.

The code below shows how to ask server for something:
net = xtra("SocketServerXtra")
objConnection = net.new( #SyncClient )
-- Connect to the server
objConnection.Connect( "server_name_or_ip", 4545, "UserName" )
-- Prepare data to be sent
valSomeLingoValue = [ 1, 2, "3", [1, 2], [#propName:propValue], #etc ]
-- Sending data and waiting while server replies
valServerReply = objConnection.SomeSubject( valSomeLingoValue )
-- Seeing what server has replied
put valServerReply

Note that synchronized client object automatically maps unknown method names to Send method with appropriate subject. So calling: cnn.SomeMethod( valData ) is the same as:
cnn.Send( "SomeMethod", valData )
This mapping may simplify programming network applications by simulating remote procedure calling. Client side calls normal Lingo method and receives normal Lingo return value, while internally network message is generated and passed to the server and back.

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com