{ "info": { "author": "Damian Nowok", "author_email": "damian.nowok@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Programming Language :: Python :: 2.7", "Topic :: Software Development" ], "description": "=======\r\niSocket\r\n=======\r\n\r\n**Simple client - server library based on TCP SocketServer**\r\n\r\niSocket is a library that allows very rapid development of client - server applications in Python.\r\nIf you develop software that runs on several machines which communicate with each other this library might come in handy.\r\n\r\nMain features:\r\n\r\n- Very simple server configuration.\r\n- Easy way to transfer back and forth complex data structures (everything that is pickable can be send and receive).\r\n- iSocket structure allows clean design of your application.\r\n- Client can easily access variables on server.\r\n\r\niSocket is written in Python 2.7 and works on Windows and Linux. Source code can be found here: https://github.com/0x1001/isock\r\n\r\niSocket installation\r\n--------------------\r\nDownload zip from http://pypi.python.org/pypi/isock/ web pages. Unzip it and run::\r\n\r\n python setup.py install\r\n\r\niSocket example\r\n---------------\r\nSample code below shows usage example.\r\nYou can learn here how to start server and client and how to define server actions.\r\n\r\nList of actions used in this example:\r\n\r\n- Echo - Sends back all data to client.\r\n- Exec - Executes system call on server and transfers console output to client.\r\n- ExecHistory - Sends system call history to client.\r\n- Time - Sends current server time to client.\r\n\r\nExample::\r\n\r\n import threading\r\n from isock import Server\r\n from isock import Client\r\n from isock import Action\r\n\r\n ################################################################################\r\n ############################ Server actions ####################################\r\n ################################################################################\r\n class Echo(Action):\r\n def action(self,data):\r\n return data\r\n\r\n class Exec(Action):\r\n def __init__(self,exec_history):\r\n self.exec_history = exec_history\r\n\r\n def action(self,data):\r\n import subprocess\r\n self.exec_history.append(data)\r\n return subprocess.check_output(data,shell=True)\r\n\r\n class ExecHistory(Action):\r\n def __init__(self,exec_history):\r\n self.exec_history = exec_history\r\n\r\n def action(self,data):\r\n return self.exec_history\r\n\r\n class Time(Action):\r\n def action(self,data):\r\n import datetime\r\n return datetime.datetime.now()\r\n\r\n ################################################################################\r\n ############################ Server startup ####################################\r\n ################################################################################\r\n history = []\r\n\r\n server = Server(\"localhost\",4440)\r\n server.addAction(Echo())\r\n server.addAction(Exec(history))\r\n server.addAction(ExecHistory(history))\r\n server.addAction(Time())\r\n server_thread = threading.Thread(target=server.serve_forever)\r\n server_thread.start()\r\n\r\n ################################################################################\r\n ############################ Client session ####################################\r\n ################################################################################\r\n client = Client(\"localhost\",4440)\r\n\r\n print \"############################# Echo test ################################\"\r\n print client.runAction(Echo,\"Echo test!\")\r\n\r\n print \"############################# Exec test ################################\"\r\n print client.runAction(Exec,\"dir\")\r\n print client.runAction(Exec,[\"python\",\"-V\"])\r\n\r\n print \"############################# Exec history #############################\"\r\n print client.runAction(ExecHistory)\r\n\r\n print \"############################# Server time ##############################\"\r\n print client.runAction(Time)\r\n\r\n ################################################################################\r\n ############################ Server shutdown ###################################\r\n ################################################################################\r\n server.shutdown()\r\n server.server_close()\r\n server_thread.join()\r\n\r\niSocket server guide\r\n--------------------\r\nServer can be imported from isock::\r\n\r\n from isock import Server\r\n\r\nServer constructor takes two required arguments: ip (string) and port (int)::\r\n\r\n server = Server(\"localhost\",4440)\r\n\r\nTo add actions to server use addAction method. It takes one required argument: action (Action)::\r\n\r\n server.addAction(Echo())\r\n\r\nTo start server use serve_forever() blocking method::\r\n\r\n server.serve_forever()\r\n\r\nTo stop server use shutdown() method::\r\n\r\n server.shutdown()\r\n\r\niSocket client guide\r\n--------------------\r\nClient can be imported from isock::\r\n\r\n from isock import Client\r\n\r\nClient constructor takes two required arguments and one optional: server_ip (string), server_port (int), retry (int).\r\nDefault retry argument is set to 3. Which allows 3 retries before ClientException is raised::\r\n\r\n client = Client(\"localhost\",4440)\r\n\r\nTo run action on server use runAction() method which takes one required argument and one optional: action (Action class ref), data (any pickable data)::\r\n\r\n client.runAction(Echo,\"Echo test!\")\r\n\r\nClient method runAction() returns data send by server or rasies exception if action ended with exception on server.\r\n\r\niSocket action guide\r\n--------------------\r\nAll actions that server can perform have to inherit from Action class.\r\nAction class can be imported from isock::\r\n\r\n from isock import Action\r\n\r\nBoth client and server have to have access to user defined action classes. I suggeste to keep them in separated file that can be imported in both server and client.\r\nTo define new action create new class that inherits from Action class and overrides action() method. This method takes one required argument: data (any pickable data send by client).\r\nIf client does not send any data this argument is set to None::\r\n\r\n class Echo(Action):\r\n def action(self,data):\r\n return data\r\n\r\nMethod action() returns data that are send back to client.\r\n\r\nTo access server variable in your action class define constructor that stores reference to server variable as attribute, which you can then access in action method::\r\n\r\n class ExecHistory(Action):\r\n def __init__(self,exec_history):\r\n self.exec_history = exec_history\r\n\r\n def action(self,data):\r\n return self.exec_history\r\n\r\nContribution\r\n------------\r\nEveryone is welcome to contribute to this project. Source code is available on GitHub.\r\nhttps://github.com/0x1001/isock", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/isock/", "keywords": "socket, socket server, tcpserver", "license": "LICENSE.txt", "maintainer": "", "maintainer_email": "", "name": "iSock", "package_url": "https://pypi.org/project/iSock/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/iSock/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/isock/" }, "release_url": "https://pypi.org/project/iSock/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Simple client - server library based on TCP SocketServer", "version": "1.0.0" }, "last_serial": 1029795, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "a7903c28ee66a724e62102a8e293cdb1", "sha256": "505090f0e0759efa537cee526c27cca1e9a6b960f220553b5ae1a3b6aec709b8" }, "downloads": -1, "filename": "iSock-1.0.0.zip", "has_sig": false, "md5_digest": "a7903c28ee66a724e62102a8e293cdb1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12300, "upload_time": "2014-03-14T16:35:54", "url": "https://files.pythonhosted.org/packages/d4/e6/472566c545fb32eaa8a76cb6bc1f59fd09d69a635c96b3047914ac6729fd/iSock-1.0.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a7903c28ee66a724e62102a8e293cdb1", "sha256": "505090f0e0759efa537cee526c27cca1e9a6b960f220553b5ae1a3b6aec709b8" }, "downloads": -1, "filename": "iSock-1.0.0.zip", "has_sig": false, "md5_digest": "a7903c28ee66a724e62102a8e293cdb1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12300, "upload_time": "2014-03-14T16:35:54", "url": "https://files.pythonhosted.org/packages/d4/e6/472566c545fb32eaa8a76cb6bc1f59fd09d69a635c96b3047914ac6729fd/iSock-1.0.0.zip" } ] }