NetCompanionSet xtras for Macromedia DirectorServer component of SocketServerXtra
Server object is a key component of SocketServerXtra. Once created and started it serves as Internet server by listening connection requests to the specified port, receiving and sending data according to MUS protocol.
To create server object use xtra-level New method:
objServer = xtra("SocketServerXtra").new( #Server )
Use Start( nPortNumber ) method to start listening the incoming connections and messages on the specified port. Calling this method makes server object to open listening socket on the specified port and create the thread for handling network messages asynchronously. While Director's main thread is running your Lingo code, server's thread may receive incoming messages and send outgoing messages.
The SocketServerXtra automatically handles incoming connection requests and places incoming messages into the queue. Your Lingo code should handle incoming messages by picking them up from the queue one by one and replying to them. Once server is running you should periodically retrieve incoming messages from the message queue and reply to them. Use ReadNext() method to retrieve the next message from the queue. It returns true if the next message is available.
Use Subject and SenderId properties to get these properties of the current message. Data property returns the Lingo value passed as a contents of the message.
Use Reply( valData ) method to reply to the current message. Otherwise you may call DropConnection() to drop connection with the client who posted the current message.
Connections property returns the list of addresses of currently connected clients. Using DropConnection( strAddress ) you may drop the connection with specific client.
This sample shows basic server functionality:
property m_objServer
on beginSprite me
net = xtra("SocketServerXtra")
m_objServer = net.new( #Server )
-- Start server bound to the port 4545
m_objServer.Start( 4545 )
end
on exitFrame me
-- Read available incoming messages one by one
repeat while objServer.ReadNext()
-- Read what is passed
valIncomingData = oServer.Data
strSubject = oServer.Subject
-- Prepare reply based on incoming data
valOutcomingData = valIncomingData
-- Reply to the message
oServer.Reply( valOutcomingData )
end repeat
end
|