Control Xtra
ABOUT
Created by Kevin Richard Fink
April 5th 2007
THIS XTRA IS PROVIDED AS IS, WITHOUT ANY IMPLIED WARRANTEE! FOLLOW INSTRUCTIONS CAREFULLY AND USE AT YOUR OWN RISK!
This is a work in progress xtra, as such some features are not yet fully
operational. Here is the current status of each call:
Complete features: (stable)
GetLocalIP() -- Returns the IP address of the pc
SendUDPMessage(ip, port, msg) -- Sends a string over UDP
SendTCPMessage(ip, port, msg) -- Sends a string over TCP
HasNext() -- Returns true if their are any messages received from UDP,
TCP or HID USB
GetNext() -- Returns the next message in the queue received from UDP,
TCP or HID USB
DestroyAllThreads() -- Stops all UDP, TCP, and HID communications
GetListOfPrimes(numPrimes) -- Returns a list of primes of specified
size.
GetListOfDevices() -- Returns a list of every device connected to
the computer.
FindAndReplace(word, lookFor, replaceWith) -- Replaces a part of a
string in a string with another string. Returns the result.
FindAndReplaceAll(word, lookFor, replaceWith) -- Replaces all parts of a
string in a string with another string. Returns the result.
MessageBox(String Title, String Message) -- Returns 'OK
OkCancelBox(String Title, String Message) -- Returns 'OK' or 'Cancel'
YesNoCancelBox(String Title, String Message) -- Returns 'Yes', 'No' or 'Cancel'
YesNoBox(String Title, String Message) -- Returns 'Yes' or 'No'
RetryCancelBox(String Title, String Message) -- Returns 'Retry' or 'Cancel'
AbortRetryIgnoreBox(String Title, String Message) -- Returns 'Retry', 'Ignore' or 'Abort'
WaitForUDP(port) -- Waits for a connection on TCP, DO NOT RUN TWO
THREADS ON THE SAME PORT EVER!
WaitForTCP(port) -- Waits for a connection on TCP, DO NOT RUN TWO
THREADS ON THE SAME PORT EVER!
Beta features: (unstable)
RunApp(String Path, String Args) -- Runs an exe
RunAppMinimized(String Path, String Args) -- Runs an exe minimized
RunAppMaximized(String Path, String Args) -- Runs an exe maximized
RunAppHidden(String Path, String Args) -- Runs an exe hidden
AppDone() -- Returns true if any running app has exited
IsPrime(n) -- Returns whether or not a number is prime.
GetListOfHIDDevices() -- Returns the VendorID, VersionNumber and
ProductID of all HID devices connected to your computer.
CheckWord(Word) -- Returns true if the word is spelled correctly
GetSuggestions(word) -- Returns a list of words closely matching
the specified word.
SendFile(IP, port, Filename) -- Sends a file to a waiting client
WaitForFile(port, Filename) -- Receives a file stores it as filename
isDone() -- Returns true if their are no active file transfers
Alpha features: (Untested) -- Avoid using these
SendDataToHIDDevice(Message) -- sends a message up to 64kbytes to
the first active USB device... avoid multiple USB connections on the same
xtra object. Returns -1 if you did not create a USB connection.
InitGetDataFromHIDDevice( vendorID, ProductID, VersionNumber) --
Creates a communication for the specified USB device
Pre-Alpha: -- Use at your own risk, these aren't even documented! Please I need someones help to test these, it was originally programmed to connect to my website database but my host does not allow incomming connections outside of its server. If you have a database you would allow me to connect to, to finish this thing off let me know: kfink@nvisionstudio.com
ConnectToSQL Object me, String Address, String UserName, String Password -- Connects to an SQL Server
QuerySQL Object me, String Query -- Preforms a query on a SQL Server, returns results
DisconnectFromSQL Object me -- Closes the current SQL server
HasSQLConnection Object me -- Returns true if their is an active SQL connection
QuickSQLQuery Object me, String Address, String Username, String Password, String Query -- Connects, queries and disconnects from an SQL Server
SPELL CHECK BENCHMARK AND CHALLENGE TO THE COMPETITORS
Can your Xtra beat my score? Prove it! Sign up and download the benchmark application used for these results. Who needs claims like "Very Fast" or "Lightning Fast", here is the performance you should expect on the given test configuration. Contact me at kfink@nvisionstudio.com to add your results!
Test Configuration:
- Windows XP x64
- Intel Core 2 E6600 @ 2.4ghz (Dual Core - 2x 2.4ghz)
- 2gb Dual Channel (2x1gb) OCZ Platinum DDR2 PC6400
- Geforce 8800GTS 640mb
- Using 400,000 word database.
| Word Count | Generate corrections for ALL words | Check spelling for ALL words | Time spent in loop |
|---|---|---|---|
| 1,000 | 0.6667 seconds |
0.1666 seconds |
0.0000 seconds |
| 5,000 | 3.6500 seconds |
0.3500 seconds |
0.2667 seconds |
| 10,000 | 7.8000 seconds |
1.2000 seconds |
1.0833 seconds |
| 50,000 | 61.5833 seconds |
27.6167 seconds |
26.2000 seconds |
| 100,000 | 176.9667 seconds |
108.6333 seconds |
106.7500 seconds |
* The times displayed are for the total time taken.
* This test uses RTF text members rather then fields to mimic real life behaviour in applications that will actually use it. To find the actual time taken by the xtra, subtract the time spent in loop.
INSTALLATION
Simply extract and copy "ControlXtra.x32" to your xtra directory of your Director Installation
HOW TO USE
-----------------------------------------------------------------------------
RunApp(Object me, String Path, String Args)
DESCRIPTION:
Runs an exe
USAGE:
object = new(xtra "ControlXtra")
object.RunApp("C:\Windows\Notepad.exe","")
--USE WITH APP DONE
on enterframe
if object.appDone() then
alert "Application Closed!"
end if
end if
-----------------------------------------------------------------------------
RunAppMinimized(Object me, String Path, String Args)
DESCRIPTION:
Runs an exe minimized
USAGE:
object = new(xtra "ControlXtra")
object.RunAppMinimized("C:\Windows\Notepad.exe","")
--USE WITH APP DONE
on enterframe
if object.appDone() then
alert "Application Closed!"
end if
end if
-----------------------------------------------------------------------------
RunAppMaximized(Object me, String Path, String Args)
DESCRIPTION:
Runs an exe maximized
USAGE:
object = new(xtra "ControlXtra")
object.RunAppMaximized("C:\Windows\Notepad.exe","")
--USE WITH APP DONE
on enterframe
if object.appDone() then
alert "Application Closed!"
end if
end if
-----------------------------------------------------------------------------
RunAppHidden(Object me, String Path, String Args)
DESCRIPTION:
Returns an exe hidden
USAGE:
object = new(xtra "ControlXtra")
object.RunAppHidden("C:\Windows\Notepad.exe","")
--USE WITH APP DONE
on enterframe
if object.appDone() then
alert "Application Closed!"
end if
end if
-----------------------------------------------------------------------------
AppDone (Object me)
DESCRIPTION:
Returns true if any application you called has closed
USAGE:
object = new(xtra "ControlXtra")
object.RunApp("C:\Windows\Notepad.exe","")
on enterframe
if object.appDone() then
alert "Application Closed!"
end if
end if
-----------------------------------------------------------------------------
MessageBox(Object me, String Title, String Message)
DESCRIPTION:
Creates a dialog box
USAGE:
object = new(xtra "ControlXtra")
object.MessageBox("Title","Message")
-----------------------------------------------------------------------------
OkCancelBox(Object me, String Title, String Message)
DESCRIPTION:
Creates an Ok/Cancel dialog box
USAGE:
object = new(xtra "ControlXtra")
if (object.OkCancelBox("Title","Message") = "Cancel") then
alert "You Cancelled!"
end if
-----------------------------------------------------------------------------
YesNoCancelBox(Object me, String Title, String Message)
DESCRIPTION:
Creates a Yes / No / Cancel dialog box
USAGE:
object = new(xtra "ControlXtra")
if (object.YesNoCancelBox("Title","Message") = "Cancel") then
alert "You Cancelled!"
end if
-----------------------------------------------------------------------------
YesNoBox(Object me, String Title, String Message)
DESCRIPTION:
Creates a Yes / No dialog box
USAGE:
object = new(xtra "ControlXtra")
if (object.YesNoBox("Title","Message") = "Yes") then
alert "You selected YES!"
end if
-----------------------------------------------------------------------------
RetryCancelBox(Object me, String Title, String Message)
DESCRIPTION:
Creates a Retry / Cancel dialog box
USAGE:
object = new(xtra "ControlXtra")
if (object.RetryCancelBox("Title","Message") = "Cancel") then
alert "You Cancelled!"
end if
-----------------------------------------------------------------------------
AbortRetryCancelBox(Object me, String Title, String Message)
DESCRIPTION:
Creates a Abort / Retry / Cancel dialog box
USAGE:
object = new(xtra "ControlXtra")
if (object.AbortRetryCancelBox("Title","Message") = "Cancel") then
alert "You Cancelled!"
end if
-----------------------------------------------------------------------------
WaitForUDP (Object me, Integer PortNumber)
DESCRIPTION:
This function creates a thread that looks for UDP messages on the
requested port.
USAGE:
object = new(xtra "ControlXtra")
object.WaitForUDP( 1627 )
NOTE:
To retrieve messages you will have to use getNext() and
hasNext().
-----------------------------------------------------------------------------
WaitForTCP (Object me, Integer PortNumber)
DESCRIPTION:
This function creates a thread that looks for TCP messages on the
requested port.
USAGE:
object = new(xtra "ControlXtra")
object.WaitForUDP( 1627 )
NOTE:
To retrieve messages you will have to use getNext() and
hasNext().
-----------------------------------------------------------------------------
SendUDPMessage (Object me, String IP, Integer PortNumber, String Message)
DESCRIPTION:
This function sends a UDP packet containing your message to the
specified port
USAGE:
object = new(xtra "ControlXtra")
object.sendUDPMessage("192.168.0.100", 1627, "MY MESSAGE")
-----------------------------------------------------------------------------
SendTCPMessage (Object me, String IP, Integer PortNumber, String Message)
DESCRIPTION:
This function sends a TCP packet containing your message to the
specified port
USAGE:
object = new(xtra "ControlXtra")
object.sendTCPMessage("192.168.0.100", 1627, "MY MESSAGE")
-----------------------------------------------------------------------------
HasNext (Object me)
DESCRIPTION:
This function returns true if their are messages that have not yet
been processed.
USAGE:
on startMovie
global object
object = new(xtra "ControlXtra")
object.waitForUDP(1627)
object.sendUDPMessage("192.168.0.100", 1627, "HERE IS A SAMPLE MESSAGE")
end
on enterFrame me
global object
if object.hasNext() then
alert "THERE IS A NEW MESSAGE!!"
end if
end
-----------------------------------------------------------------------------
GetNext (Object me)
DESCRIPTION:
This function returns any messages that have not yet been sent to
director, or -1 if their is no messages. For USB it will return a string, for
TCP/UDP it will return a message in the format [message, sourceIP]
USAGE:
on startMovie
global object
object = new(xtra "ControlXtra")
object.waitForUDP(1627)
object.sendUDPMessage("192.168.0.100", 1627, "HERE IS A SAMPLE MESSAGE")
end
on enterFrame me
global object
if object.hasNext() then
alert object.getNext()
end if
end
-----------------------------------------------------------------------------
DestroyAllThreads (Object me)
DESCRIPTION:
Basically a closing parameter in this application, it ensures that the memory is
cleaned of any remaining unread messages and closes all open ports that it was using.
USAGE:
on startMovie
global object
object = new(xtra "ControlXtra")
object.waitForUDP(1627)
object.sendUDPMessage("192.168.0.100", 1627, "HERE IS A SAMPLE MESSAGE")
end
on enterFrame me
global object
if object.hasNext() then
alert object.getNext()
end if
end
on StopMovie
global object
if object <> void then
object.DestroyAllThreads()
end if
end
-----------------------------------------------------------------------------
GetListOfPrimes (Object me)
DESCRIPTION:
Returns a list containing the number of prime numbers specified
USAGE:
object = new(xtra "ControlXtra")
put object.getListOfPrimes(100)
-----------------------------------------------------------------------------
isPrime (Object me)
DESCRIPTION:
Returns if the specified number is prime, seems to screw up for very
large numbers, however it is really very fast.. quite possibly the fastest in
existence today.
USAGE:
object = new(xtra "ControlXtra")
put object.isPrime(97)
-----------------------------------------------------------------------------
GetListOfDevices (Object me)
DESCRIPTION:
Returns a list containing all devices connected to the pc.
USAGE:
object = new(xtra "ControlXtra")
put object.getListOfDevices()
-----------------------------------------------------------------------------
GetListOfHIDDevices (Object me)
DESCRIPTION:
Returns a list containing all connected HID devices connected to the pc.
Each entry of the list consists of a versionID, versionNumber and a productID
USAGE:
object = new(xtra "ControlXtra")
put object.getListOfHIDDevices()
-----------------------------------------------------------------------------
SendDataToHIDDevices (Object me, String Message)
DESCRIPTION:
Sends a message to a connected HID device. Extremely unstable.
USAGE:
object = new(xtra "ControlXtra")
put object.sendDataToHIDDevices("Message")
-----------------------------------------------------------------------------
InitGetDataFromHIDDevice (Object me, Integer vendorID, Integer productID, Integer versionNumber)
DESCRIPTION:
Starts a thread to get all incoming data from the specified USB device...
0 for any value becomes a wildcard. Be as specific as possible to connect to the
right device. Extremely unstable.
USAGE:
object = new(xtra "ControlXtra")
put object.InitGetDataFromHIDDevice(vendorID, productID, versionNumber)
-----------------------------------------------------------------------------
checkWord (Object me, String word)
DESCRIPTION:
Returns true if the word is spelled correctly, false if it is not.
USAGE:
object = new(xtra "ControlXtra")
put object.checkWord("test")
-----------------------------------------------------------------------------
getSuggestions (Object me, String word)
DESCRIPTION:
Returns a list of strings closely matching the word specified
USAGE:
object = new(xtra "ControlXtra")
if object.checkWord("testz") then
alert object.getSuggestions("testz")
end if
-----------------------------------------------------------------------------
findAndReplace (Object me, String word, String lookFor, String replaceWith)
DESCRIPTION:
Replaces a string within a string with the specified string.
USAGE:
object = new(xtra "ControlXtra")
alert output.findAndReplace("Testing", "tin", "lg")
outputs:
"Teslgg"
-----------------------------------------------------------------------------
findAndReplaceAll (Object me, String word, String lookFor, String replaceWith)
DESCRIPTION:
Replaces a string within a string with the specified string.
USAGE:
object = new(xtra "ControlXtra")
alert output.findAndReplace("Testingtin", "tin", "lg")
outputs:
"Teslgglg"
-----------------------------------------------------------------------------
SendFile (Object me, String IP, Integer Port, String Filename)
DESCRIPTION:
Sends a file over TCP
USAGE:
object = new(xtra "ControlXtra")
output.SendFile("192.168.0.1",1222,"C:\input")
-----------------------------------------------------------------------------
WaitForFile (Object me, Integer Port, String Filename)
DESCRIPTION:
Retrieves a file from TCP (initialize this before you send a file)
USAGE:
object = new(xtra "ControlXtra")
output.SendFile(1222,"C:\output")
-----------------------------------------------------------------------------
IsDone (Object me)
DESCRIPTION:
Returns true if their are no active file connection.
USAGE:
object = new(xtra "ControlXtra")
put object.isDone()
-----------------------------------------------------------------------------
FREQUENTLY-ASKED-QUESTIONS
WILL THE SOURCE CODE BE PROVIDED?:
No, but if you would like modifications, contact me and we can work
something out.
WHAT DOES MULTITHREADED MEAN IN TERMS OF THIS XTRA?:
Well for one, if you have multiple cores or cpus this application will
make work for them to do. The threading comes in the server portion of it,
each time you call WaitForUDP(port) you create a new thread that exclusively
handles incoming messages on that port. There is also a main thread that
handles calles for messages and sending messages, all other procedures share
one thread.
WHY CREATE THIS XTRA? CAN'T YOU USE MULTIUSER XTRA INSTEAD?
Macromedia/Adobe no longer supports the MULTIUSER XTRA. In short,
its a horribly unfinished and confusing mess of an xtra. If you've had the
displeasure of using that Xtra you will understand. There are also many
limitations on it, expecially with peer-2-peer connections. Limitations
include no UDP support for P2P, limit of 8 connections on P2P and finally
an ugly discontinued server app that they charge for. Self discovery is
impossible using MULTIUSER server, it can take sever seconds to try to
establish a connection with a single IP, and has absolutely no threading,
essentially you have to go at it one IP at a time.
IS IT SHOCKWAVE-SAFE ?
No, but I could provide a copy that is. Contact me if your interested!
I'm essentially holding back for more testing to ensure it will not produce any
exploits.
WHAT IS SELF-DISCOVERY?
Although not a specific function in this xtra, it makes it
possible! If your on a network and want to establish a connection with
another client that you don't have the address for. With this you can use
director to write your own self-discovery algorithm but here is the general
idea.
Find out your networks subet mask:
ex 255.255.255.0
Find out your IP
ex 192.168.0.1
Using the subnet mask and your IP, you know that clients will be in the
range. (ex from above) 192.168.0.0 to 192.168.0.255
Simply create a message with your location and send it to all other
clients in that range. ex "192.168.0.1 REQUEST_CONNECTION"
You also want to scan for messages with the "REQUEST_CONNECTION" add the
IP from that REQUEST, then send your IP and all the other clients you have
with the same message. Very quickly you will find all the clients on the
network.
