title: Pywebsocket error
body: <p>I'm new to python and websockets and would like to learn more about how to use pywebsocket.</p>
  
  <p>Currently, Im editing examples from pywebsocket package, unfortunately, I'm unable to understand my error in following code:</p>
  
  <pre><code>_GOODBYE_MESSAGE = u'Goodbye'
  
  def web_socket_do_extra_handshake(request):
      request.ws_stream.send_message("Welcome", binary=False) # Error line
      pass  # Always accept.
  
  def web_socket_transfer_data(request):
      while True:
          line = request.ws_stream.receive_message()
          if line is None:
              return
          if isinstance(line, unicode):
              request.ws_stream.send_message("Sending", binary=False)
              request.ws_stream.send_message(line, binary=False)
              if line == _GOODBYE_MESSAGE:
                  return
          else:
              request.ws_stream.send_message(line, binary=True)
  </code></pre>
  
  <p>I wanted to send "Welcome" message back to client when connection is initialized. But when I send any message from Handshake I got my websocket closed with <strong>code 1006</strong></p>
  
  <p><strong>Why is that so?</strong></p>
  
  <p>I thought the problem may be that, it is not possible to send any data during handshake, so I tried it this way:</p>
  
  <pre><code>_GOODBYE_MESSAGE = u'Goodbye'
  welcome = True
  
  def web_socket_do_extra_handshake(request):
      pass  # Always accept.
  
  def web_socket_transfer_data(request):
      while True:
          if welcome:
              welcome = False
              request.ws_stream.send_message("Welcome !", binary=False)
  
          line = request.ws_stream.receive_message()
          if line is None:
              return
          if isinstance(line, unicode):
              request.ws_stream.send_message("Sending", binary=False)
              request.ws_stream.send_message(line, binary=False)
              if line == _GOODBYE_MESSAGE:
                  return
          else:
              request.ws_stream.send_message(line, binary=True)
  </code></pre>
  
  <p>I wasn't successful in neither first or second case, could you explain <strong>what am I doing wrong</strong>? Thank you</p>
  
  <p>PS: Im running mod_pywebsocket as module of Apache (not standalone), my python version is 2.6.6; I have tried to run both of my scripts using <code>$python script_wsh.py</code> to check for syntax errors </p>