Skip to content

Instantly share code, notes, and snippets.

@sinanm89
Created September 10, 2015 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinanm89/10f971904d74b2a6f9ea to your computer and use it in GitHub Desktop.
Save sinanm89/10f971904d74b2a6f9ea to your computer and use it in GitHub Desktop.
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()
@sinanm89
Copy link
Author

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 because
exceptions.ImportError: No module named gameserver.server_main

however I can launch it via terminal no problem

@dpnova
Copy link

dpnova commented Sep 10, 2015

Why do you want to run the plugin from within django?

In production you would probably deploy the two as separate commands right?

@sinanm89
Copy link
Author

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.

@dpnova

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment