I create a simple echo server and I would like to use it for a simple webserver example.
Until now I have the server:
Server.py
from socket import *
import threading
import thread
def handler(clientsock,addr):
while 1:
data = clientsock.recv(BUFSIZ)
if not data:
break
msg = 'echoed:... ' + data
clientsock.send(msg)
clientsock.close()
if __name__=='__main__':
HOST = 'localhost'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)
serversock = socket(AF_INET, SOCK_STREAM)
serversock.bind(ADDR)
serversock.listen(2)
while 1:
print 'waiting for connection...'
clientsock, addr = serversock.accept()
print '...connected from:', addr
thread.start_new_thread(handler, (clientsock, addr))
I would like to use websockify and I found that is able to wrap an existing program using:
./websockify 2023 -- PROGRAM ARGS
How can I run the the previous server using the above command? Can I run websockify on one machine while the server.py is running on a different machine? If yes. How can I modify the above command?
Can someone provide a simple HTML5 example to show me how the client.html should look like? Please keep in mind that I want to be able to use the example with browsers that do not have native websocket support. I think websockify is able to do that using web-socket-js.
They state: It has transparent support for binary data and has automatic fallback to the web-socket-js Flash Websocket shim/polyfill if the browser does not support WebSockets natively