上記2つの答えは正しいです。しかし、すでにというスペルを実装していると考えて、を入力した場合、をとして実行してください。別のプロセスと同じマシンで実行することで開始することができます - localhost:PORT
。今のところ非常にシンプルなバイナリプロトコルインターフェイスを既に持っているようです。標準libのsocket
インターフェイスをブロッキングモードで使って、同様に単純なPythonクライアントを実装できます。
しかし、私はtwisted.web
で遊んで、簡単なWebインターフェイスを公開することをお勧めします。 JSONを使用してデータをシリアライズおよびデシリアライズすることができます。これはDjangoで十分サポートされています。ここでは非常に簡単な例です:
import json
from twisted.web import server, resource
from twisted.python import log
class Root(resource.Resource):
def getChild(self, path, request):
# represents/on your web interface
return self
class WebInterface(resource.Resource):
isLeaf = True
def render_GET(self, request):
log.msg('GOT a GET request.')
# read request.args if you need to process query args
# ... call some internal service and get output ...
return json.dumps(output)
class SpellingSite(server.Site):
def __init__(self, *args, **kwargs):
self.root = Root()
server.Site.__init__(self, self.root, **kwargs)
self.root.putChild('spell', WebInterface())
そして、あなたは、次のスケルトン.tac
ファイルを使用することができ、それを実行するために:他のファーストクラスのサービスを使用すると、別のマシンのいずれかでそれを実行することを可能にするよう
from twisted.application import service, internet
site = SpellingSite()
application = service.Application('WebSpell')
# attach the service to its parent application
service_collection = service.IServiceCollection(application)
internet.TCPServer(PORT, site).setServiceParent(service_collection)
はあなたのサービスを実行しますウェブインタフェースを公開することで、リバースプロキシロードバランサの背後で水平に簡単にスケーリングすることができます。
は既にこれを理解していました。しかし、ありがとう... –