-
Houdiniの組み込みウェブサーバーは、Python関数(またはC++拡張)をコールしてウェブリクエストを制御できるようにC++で記述されたマルチスレッドなHTTPサーバーです。
-
この主な用途は、Houdiniシーンデータにアクセスできるサービス指向のAPIを構築することです。
-
グローバルな組み込みウェブサーバーは、起動中のHoudiniインスタンス毎に1つしか起動できません。
-
hwebserver.urlHandlerデコレータを使用してパスハンドラーを指定したり、hwebserver.apiFunctionデコレータを使用してAPIを構築することができます。
-
それから、hwebserver.runを使用して組み込みウェブサーバーを開始することができます:
hwebserver.run(8008, debug=True)
Note
この関数は、非グラフィカルなセッションからコールした場合には 何も返しません (サーバーが中断された場合、または、サーバーコードがhwebserver.requestShutdownをコールした場合を除く)。
-
コマンドラインからサーバーを試すには:
-
server.py
ファイル内に以下のコードを記述します:server.py
import hou import hwebserver @hwebserver.urlHandler("/") def my_handler(request): return hwebserver.Response( "Hello from Houdini %s" % hou.applicationVersionString()) if __name__ == "__main__": hwebserver.run(8008, debug=True)
-
Houdini環境がセットアップされたシェル内で、
hython server.py
を実行します。 -
ブラウザから
http://127.0.0.1:8008/
にアクセスすると、その出力が表示されます。 -
LinuxやMacの場合は⌃ Ctrl + C、Windowsの場合は⌃ Ctrl + Break/⌃ Ctrl + ScrLkを押すことでサーバーが停止されます。
-
サブトピック
クラス
-
A request made to Houdini’s web server.
-
A response made back from Houdini’s web server.
-
A file uploaded in a request made to Houdini’s web server.
-
The general purpose HTTP handler.
-
The general purpose Async HTTP handler.
-
Base class for WebSocket support with the embedded server.
開始と停止
-
Starts Houdini’s web server.
-
Tells Houdini’s web server to shut down after serving all open requests.
-
Returns True if Houdini’s web server was started in debug mode debug=True in )
ウェブリクエストの処理とレスポンスの返し
-
Decorator for functions that handle requests to Houdini’s web server.
-
Generates a Response object representing an HTTP error.
-
Generates a Response object representing a 404 Not Found HTTP error.
-
Generates a Response object that sends the contents of a file.
-
Generates a Response object representing a 301 Moved or 302 Found HTTP response.
-
hwebserver.registerStaticFilesDirectory
Tells Houdini’s web server to check the given directory for files to automatically serve for URLs that match the given path prefix.
-
Tells Houdini’s web server to use the specified prefix as a handler to serve opdef requests.
-
Function used to register a wsgi capable application such as django to be used on a path prefix.
-
Function used to register a asgi capable application such as django to be used on a path prefix.
-
Set the settings for a specific port.
ウェブソケット
-
Base class for WebSocket support with the embedded server.
-
Decorator for registering WebSocket classes with Houdini’s web server.
APIコール
-
Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.
-
Raise this exception in apiFunction handlers to indicate an error.