Created
September 10, 2015 14:32
-
-
Save sinanm89/10f971904d74b2a6f9ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zope.interface import implements | |
from twisted.python import usage | |
from twisted.plugin import IPlugin | |
from twisted.application.service import IServiceMaker | |
from twisted.application import internet | |
from gameserver.server_main import VersusGameFactory, logger | |
class Options(usage.Options): | |
optParameters = [["port", "p", 1235, "The port number to listen on."]] | |
class MyServiceMaker(object): | |
implements(IServiceMaker, IPlugin) | |
tapname = "gameserver" | |
description = "Versus game server for a singular game" | |
options = Options | |
def makeService(self, options): | |
""" | |
Construct a TCPServer from a factory defined in myproject. | |
""" | |
# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
# sock.bind(('', 0)) | |
# port = sock.getsockname()[1] | |
port = int(options["port"]) | |
logger.info('Server Started at port %s' % str(port)) | |
return internet.TCPServer(int(options["port"]), VersusGameFactory()) | |
# Now construct an object which *provides* the relevant interfaces | |
# The name of this variable is irrelevant, as long as there is *some* | |
# name bound to a provider of IPlugin and IServiceMaker. | |
serviceMaker = MyServiceMaker() |
Why do you want to run the plugin from within django?
In production you would probably deploy the two as separate commands right?
well I have the django api, models and permissions set. When the api is called to create a game a port with the tcp server will open a game for the users and when the game is finished close it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my directory structure is like so;
myproject
├── webserver
│ ├── django_stuff
├── gameserver
│ ├── init.py
│ ├── init.pyc
│ ├── pids
│ │ ├── 35215
│ │ │ ├── port35215.log
│ │ │ └── port35215.pid
│ ├── server_main.py
│ ├── server_main.pyc
│ ├── twistd.log
│ └── twisted
│ │ └── plugins
│ │ │ ├── dropin.cache
│ │ │ ├── gameserver_plugin.py
│ │ │ ├── gameserver_plugin.pyc
Im getting an error at line 8 that it cant import the
VersusGameFactory
becauseexceptions.ImportError: No module named gameserver.server_main
however I can launch it via terminal no problem