modifié: superTornado.py
nouveau fichier: test.html
This commit is contained in:
parent
00e95a2a98
commit
62bc232719
@ -1,6 +1,10 @@
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import tornado.httpserver
|
||||
import tornado.websocket
|
||||
from tornado.ioloop import PeriodicCallback
|
||||
|
||||
|
||||
from loadConf import *
|
||||
from login import *
|
||||
|
||||
@ -41,12 +45,27 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
|
||||
class VideoHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
self.write("Authorized user access")
|
||||
self.render("test.html")
|
||||
|
||||
class WSHandler(tornado.websocket.WebSocketHandler):
|
||||
def open(self):
|
||||
self.callback = PeriodicCallback(self.send_hello, 120)
|
||||
self.callback.start()
|
||||
|
||||
def send_hello(self):
|
||||
self.write_message('hello')
|
||||
|
||||
def on_message(self, message):
|
||||
pass
|
||||
|
||||
def on_close(self):
|
||||
self.callback.stop()
|
||||
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/video", VideoHandler),
|
||||
(r"/test", WSHandler),
|
||||
])
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -60,3 +79,4 @@ if __name__ == "__main__":
|
||||
http_server = tornado.httpserver.HTTPServer(application)
|
||||
http_server.listen(80)
|
||||
tornado.ioloop.IOLoop.instance().start()
|
||||
|
||||
|
30
test.html
Normal file
30
test.html
Normal file
@ -0,0 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
|
||||
function fun(){
|
||||
|
||||
alert("in fun()");
|
||||
|
||||
var val=document.getElementById("txt");
|
||||
var ws = new WebSocket("ws://localhost:8888");
|
||||
|
||||
ws.onopen = function(evt) { alert("Connection open ...");
|
||||
ws.send(val.value); };
|
||||
ws.onmessage = function(evt) {
|
||||
alert("from server: "+evt.data);
|
||||
}
|
||||
|
||||
ws.onclose = function(evt) {
|
||||
alert("Connection closed.");
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<input type="text" id="txt" />
|
||||
<button onClick="fun()">click</button>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user