summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-31 21:43:41 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-31 21:43:41 +0200
commit1193b9c68caba33f19baa4265349a89ff5a777a6 (patch)
tree63350f4f44b08a66cdc2be201174f7ec76ab96d3
parentgui socket finally works (diff)
downloadpyload-1193b9c68caba33f19baa4265349a89ff5a777a6.tar.xz
socket interface example
-rw-r--r--module/remote/ClientHandler.py3
-rw-r--r--module/remote/ClientSocket.py20
-rw-r--r--module/remote/RequestHandler.py2
-rw-r--r--module/remote/SocketServer.py3
-rwxr-xr-xpyMainGui.py2
5 files changed, 24 insertions, 6 deletions
diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py
index 6f60d5176..6f208a3f5 100644
--- a/module/remote/ClientHandler.py
+++ b/module/remote/ClientHandler.py
@@ -19,5 +19,6 @@ class ClientHandler(RequestHandler):
def proceed(self, data):
obj = self.decrypt(data)
- #evaluate object
+ if obj.function == "get_downloads":
+ print obj.response
return self.encrypt(obj)
diff --git a/module/remote/ClientSocket.py b/module/remote/ClientSocket.py
index 9c52681c7..68e6ee884 100644
--- a/module/remote/ClientSocket.py
+++ b/module/remote/ClientSocket.py
@@ -13,22 +13,35 @@ import threading
import time
from ClientHandler import ClientHandler
+from RequestObject import RequestObject
class SocketThread(threading.Thread):
def __init__(self, adress, port, pw, client):
threading.Thread.__init__(self)
+ self.setDaemon(True)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((adress, port))
self.socket = ClientSocket(sock, pw, client)
self.start()
+
def run(self):
asyncore.loop()
print "loop closed"
+ def push_exec(self, function, args=[]):
+ obj = RequestObject()
+ obj.command = "exec"
+ obj.function = function
+ obj.args = args
+ self.push(obj)
+
+ def push(self, obj):
+ self.socket.push_obj(obj)
+
class ClientSocket(asynchat.async_chat):
def __init__(self, sock, pw, client):
- asynchat.async_chat.__init__(self, conn=sock)
+ asynchat.async_chat.__init__(self, sock)
self.data = ""
self.handler = ClientHandler(client, pw)
self.set_terminator("\n")
@@ -46,3 +59,8 @@ class ClientSocket(asynchat.async_chat):
#self.push(obj+"\n")
print "data arrived"
self.data = ""
+
+ def push_obj(self, obj):
+ string = self.handler.encrypt(obj)
+ self.push(string)
+
diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py
index ec0bf0414..dd4fdeb5f 100644
--- a/module/remote/RequestHandler.py
+++ b/module/remote/RequestHandler.py
@@ -60,7 +60,7 @@ class RequestHandler:
enc_str = self.bf.encrypt(enc_str)
enc_str = base64.standard_b64encode(enc_str)
- return enc_str
+ return enc_str + "\n"
diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py
index e1b41dd1d..c9979adb8 100644
--- a/module/remote/SocketServer.py
+++ b/module/remote/SocketServer.py
@@ -35,7 +35,6 @@ class MainServerSocket(asyncore.dispatcher):
def handle_accept(self):
newSocket, address = self.accept()
print "Connected from", address
- print newSocket
SecondaryServerSocket(newSocket, self.pycore)
def handle_close(self):
print "going to close"
@@ -54,7 +53,7 @@ class SecondaryServerSocket(asynchat.async_chat):
self.data += data
def found_terminator(self):
rep = self.handler.proceed(self.data)
- self.sendall(rep+"\n")
+ self.push(rep)
print "data arrived"
self.data = ""
#having fun with the data
diff --git a/pyMainGui.py b/pyMainGui.py
index 83dcad885..c84f1ed01 100755
--- a/pyMainGui.py
+++ b/pyMainGui.py
@@ -73,7 +73,7 @@ class Pyload_Main_Gui(wx.Frame):
# socket
self.thread = SocketThread("localhost", 7272, "pwhere", self)
- self.thread.socket.push("nonsense\n\n")
+ self.thread.push_exec("get_downloads")
# Menubar
menubar = wx.MenuBar()