Skip to content

Instantly share code, notes, and snippets.

@sinanm89
Created September 10, 2015 14:32
Show Gist options
  • 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

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