위의 두 답변이 맞습니다. 그러나 이미 맞춤법 을 구현 한 경우 을 실행하면으로 실행됩니다. localhost:PORT
에서 별도의 프로세스와 동일한 시스템에서 실행하여 시작할 수 있습니다. 지금 당장은 이미 아주 간단한 바이너리 프로토콜 인터페이스를 가지고있는 것으로 보인다. 블로킹 모드에서 표준 lib의 socket
인터페이스를 사용하여 똑같이 간단한 파이썬 클라이언트를 구현할 수있다.
그러나 twisted.web
으로 놀고 간단한 웹 인터페이스를 드러내는 것이 좋습니다. JSON을 사용하여 데이터를 직렬화 및 비 직렬화 할 수 있습니다. 이는 장고가 잘 지원합니다.
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)
을 여기에 매우 빠른 예제 웹 인터페이스를 노출하면 역방향 프록시로드 밸런서를 수평으로 쉽게 확장 할 수 있습니다.
이미 알아 냈습니다. 하지만 고마워. –