0

I'm trying to write a simple websocket client to connect to a device. However the device expects a username and password and I'm having quite a bit of trouble finding how to pass that with the connection.

This is one of the ways I've tried it.

var io = require('socket.io-client'),
    socket = io.connect('192.168.1.25/eventstream', 
    {username: 'Admin', password: 'Admin'});

I'm sorry if this is something simple, node/socket.io are new to me so searching with the right terms is difficult. Any links are appreciated.

12
  • do you have documentation for the device? I suspect that username and password are supposed to be passed after a successful connection. Commented Jan 23, 2015 at 21:10
  • Yes the "Authorization: Basic QWRtaW46QWRtaW4=" header is all it shows though. Full Request URI: ws://192.168.60.80/stream=true HTTP - WebSocket /stream=true HTTP/1.1 Host: 192.168.60.80 Sec-WebSocket-Version: 13 Sec-WebSocket-Key: sL7YXg61Aqzr7HXA3M9Gow== Authorization: Basic QWRtaW46QWRtaW4= Connection: keep-alive, Upgrade Upgrade: websocket Commented Jan 23, 2015 at 21:19
  • this is just a stab in the dark, but since it's basic authentication you can try io.connect('http://Admin:[email protected]/eventstream') Commented Jan 23, 2015 at 21:24
  • Nope :( that didn't work. When I do io.on('connect'.... it spits out "connected: false, disconnected: true" Commented Jan 23, 2015 at 21:29
  • 1
    have you tried socket = io.connect('192.168.1.25/eventstream', {Sec-WebSocket-Version: 13, Sec-WebSocket-Key: 'sL7YXg61Aqzr7HXA3M9Gow==', Authorization: 'Basic QWRtaW46QWRtaW4=', Connection: 'keep-alive, Upgrade', Upgrade: 'websocket'} ? Commented Jan 23, 2015 at 21:56

1 Answer 1

2

Woot! I feel a bit sheepish but...using https://github.com/theturtle32/WebSocket-Node I was able to get a connection.

var WebSocket = require('websocket').client;
var client = new WebSocket();
...
client.connect('ws://192.168.1.2', null, null, 
{'Authorization':'Basic QWRtaW46QWRtaW4='}, null);

Likely my lack of familiarity with javascript. Thanks for all the suggestions Aaron & trex005!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.