何に使うかよくわからないが
サーバに対話的なスクリプトを仕込んでおくと
組み込みが用意なバックエンドAPIが作れそうなので試してみた。
対話しないのなら普通にHTTPでいいんだけど。
AAの作成にはfigletを使った。
サーバ側
server.py
import tornado.ioloop import tornado.web import tornado.websocket import tornado.template import datetime aa = """ _ _ ___ ____ __ _ ___ | | _(_) / _ \/ ___| / _` |/ _ \| |/ / | | | | \___ \ | (_| | (_) | <| | | |_| |___) | \__,_|\___/|_|\_\_| \___/|____/ """ login = "Current login: "+str(datetime.date.today()) hellomsg = aa+login class MainHandler(tornado.web.RequestHandler): def get(self): loader = tornado.template.Loader(".") self.write(loader.load("index.html").generate()) class WSHandler(tornado.websocket.WebSocketHandler): def open(self): print 'connection opened...' self.write_message(hellomsg) def on_message(self, message): self.write_message("The server says: " + message + " back at you") print 'received:', message def on_close(self): print 'connection closed...' application = tornado.web.Application([ (r'/ws', WSHandler), (r'/', MainHandler), (r"/(.*)", tornado.web.StaticFileHandler, {"path": "./resources"}), ]) if __name__ == "__main__": application.listen(9090) tornado.ioloop.IOLoop.instance().start()
サーバ起動
$ python server.py
wscatインストール
$ npm install -g ws
クライアントアクセス
$ wscat -c ws://localhost:9090/ws connected (press CTRL+C to quit) < _ _ ___ ____ __ _ ___ | | _(_) / _ \/ ___| / _` |/ _ \| |/ / | | | | \___ \ | (_| | (_) | <| | | |_| |___) | \__,_|\___/|_|\_\_| \___/|____/ Current login: 2014-10-24 > ls < The server says: ls back at you > ls < The server says: ls back at you disconnected