0

I am trying to create a python 3 program that sets up a websocket client and send some data to it.

I have learned that the data it sends isn't exactly in ASCII and if i try socket.send(b"Hello websocket!"), this will fail for me. I have used the create your own test example on http://www.websocket.org/echo.html and when I wiresharked the data that it sends to the websocket, it wireshark doesn't display the sent data in readable characters (I'm assuming its been translated by some algorithm). Also, when I view the data it sent in c array's, it's different values every time I run it. I can't figure out how it translates the "WebSocket rocks" text into something that will work. How would I be able to accomplish translating the message being sent in python? I guess the true question is that what is the formula javascript uses for send() to take the parameters from a string into the data necessary that I can port to python so that it does the same thing.

cellsheet
  • 450
  • 1
  • 4
  • 21
  • Have you chosen secure web sockets (wss://) ? – Alastair McCormack Aug 17 '13 at 19:28
  • the real site im connecting to once i figure it out just uses ws://. it also seems as though in javascript that websocket.send() does it automatically while in python it doesn't. – cellsheet Aug 17 '13 at 19:31
  • Can you clarify what doesn't work? Your Python code or Wiresharking the example at websocket.org? – Alastair McCormack Aug 17 '13 at 19:40
  • the python code won't send the data the same way that websocket.send() would in javascript. python seems to send it in ASCII while javascript seems to send it in another encoding. – cellsheet Aug 17 '13 at 19:46
  • did you send headers to server? – eri Aug 17 '13 at 19:50
  • Is your browser configured with an SSL Proxy? – Alastair McCormack Aug 17 '13 at 19:56
  • yes, the headers are ok. I got the correct http response. its just the actual data thats being sent afterwords is different in character types. Also I have my chrome set at whatever is default in settings. – cellsheet Aug 17 '13 at 19:57
  • Browser->Server comms are masked. See http://stackoverflow.com/questions/8125507/how-can-i-send-and-receive-websocket-messages-on-the-server-side. It looks like you'll need to implement a Python masking method. It'll be really interesting to see the code if you manage it – Alastair McCormack Aug 17 '13 at 20:50

0 Answers0