Okay, I have had some time to work on this and I think that I have the multi-threading working. If someone wants to take a look at this code to make sure I am thinking sanely that would be great. NOTE - This is the current code I have for the "server" which is run from the client's computer.
CODE
import Queue
import socket
import threading
policyTxt = "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"2727\" /></cross-domain-policy>\0"
class ClientThread(threading.Thread):
def run(self):
while True:
client = clientPool.get()
if client != None:
print 'Received connection:', client[1][0]
while True:
message = client[0].recv(1024)
if message:
print message
if message != "<policy-file-request/>\0":
reply = "ECHO: "+ message
client[0].send(reply)
if message == "<policy-file-request/>\0":
client[0].send(policyTxt)
if message == "<close-connection/>\0":
print "Connection closed: ", client[1]
client[0].close();
break;
clientPool = Queue.Queue(0)
for x in xrange(2):
ClientThread().start()
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 2727))
server.listen(5)
while True:
clientPool.put(server.accept())
If you want to see how it works so far here is a link to the client application (the flash front-end)
http://reigninggames.com/tests/flash/socks/basics_01.htmlInstructions on how to run it:
1. Make sure that you have python installed on your computer
2. Create a new file (using notepad, or whatever) that you copy and paste the code above to.
2a. Save this file as a
.py file (if you try .pyw it won't show anything)
3. Make sure your firewall is configured to allow python to communicate and access the internet (otherwise this will probably not work)
4. Run the python file
5. Click on the link above and see how it works
5a. NOTE - You will need to have the python file running otherwise the connection will fail.
5b. The
policyTxt variable should not be touched. This is what is allowing the Flash to connect to your computer.
Usage:
At this point in time the usage is very simple. You can type things into the textbox at the bottom of the flash app and then click the send msg button and it will send the message to the server (client computer), which will print out the text and send a reply which is this:
ECHO: <user-entered-text>The flash is configured to output everything that it recieves from the server like so:
Recieved: <server-text>Commands:
At this point the commands that I have enabled in the server are simply as follows:
<close-connection/> - Tells the server to close the socket connection.
NOTE - Commands have to be sent to the server via the Flash. They can't be directly input to the server.
Tell me what you think.