i have this opensource code which is used to echo back response to web-socket requests:
_GOODBYE_MESSAGE = 'Goodbye'
def web_socket_do_extra_handshake(request):
pass # Always accept.
def web_socket_transfer_data(request):
while True:
line = request.ws_stream.receive_message()
if line == "hello":
request.ws_stream.send_message("hello was sent")
if line == "bye":
request.ws_stream.send_message("bye was sent")
if line is None:
return
#request.ws_stream.send_message(line)
if line == _GOODBYE_MESSAGE:
return
now problem is i want to modify it (transfer_data method) so that inside the while loop lets say it checks the string line if it equals certains text, it should return something else to client and if line equals something else it shoud return a different string.
I have tried lot but it does not seem to work, i know it is very basic, but can someone please help me with this.
Another thing i want to do is to be able to add delay to response say 5 seconds, but import time does not work. I get error, please help with this.