Saturday, February 28, 2015

WebSocket - an Initiatial investigation

Thought to try something on web socket, and landed on a web page like this: https://github.com/elabs/mobile-websocket-example/blob/master/README.md

Downloaded all the source files and it had Android, iOS, Browser, clients and a ruby based server. 

I did not have the ruby installation correctly it seems, so i had to download and install the ruby. Did the below command and installed the ruby 

sudo gem install bundler 

this installed and from the server directory, just ran the command “bundle install” 

So this specifically installs the web socket server 

bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/..
/Library/Ruby/Gems/2.0.0/gems/bundler-1.8.3/lib/bundler.rb:317: warning: Insecure world writable dir /usr/local in PATH, mode 040777
Installing eventmachine 1.0.3
Installing http_parser.rb 0.5.3
Installing em-websocket 0.4.0


to start the server, just need to call “ruby server.rb”

Now, connect from the client which is given along with the server browser code given. 


administrators-MacBook-Pro-3:server retheesh$ ruby server.rb
[[:initialize]]

[[:receive_data,
  "GET / HTTP/1.1\r\nHost: localhost:8080\r\nConnection: Upgrade\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\nOrigin: null\r\nSec-WebSocket-Version: 13\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-US,en;q=0.8\r\nSec-WebSocket-Key: 8EWR5n2GnRKyGWuX5RSDuA==\r\nSec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n\r\n"]]

[[:accepting_ws_version, 13]]

[[:upgrade_response,
  "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: VsXGAOPgndpkYnXSFZ7pb9CKbZc=\r\n\r\n"]]

[[:sending_frame, :text, "1 connected"]]

[[:receive_data,
  "\x81\xFE\x00\x84\xAD %\x83\xE5EI\xEF\xC2\x00C\xF1\xC2M\x05\xCE\xC2ZL\xEF\xC1A\n\xB6\x83\x10\x05\xAB\xE0AF\xEA\xC3TJ\xF0\xC5\e\x05\xCA\xC3T@\xEF\x8DmD\xE0\x8Dov\xA3\xF5\x00\x14\xB3\xF2\x11\x15\xDC\x9C\t\x05\xC2\xDDPI\xE6\xFAEG\xC8\xC4T\n\xB6\x9E\x17\v\xB0\x9B\x00\r\xC8\xE5th\xCF\x81\x00I\xEA\xC6E\x05\xC4\xC8CN\xEC\x84\x00f\xEB\xDFOH\xE6\x82\x14\x15\xAD\x9D\x0E\x17\xB1\x9C\x14\v\xB2\x9C\x15\x05\xD0\xCCFD\xF1\xC4\x0F\x10\xB0\x9A\x0E\x16\xB5"]]

References: 

No comments:

Post a Comment