Neurosky Mindwave & Websockets - html

I'm currently trying to make a connection to the Neurosky Mindwave sensor using a websocket in HTML5. The Mindwave makes use of the Thinkgear Connector which I in turn use to connect to. I connect to the Thinkgear Connector using the default host address 127.0.0.1 with port 13854.
Basically all I do is this:
var socket = new WebSocket('ws://127.0.0.1:13854');
If I run the script the Thinkgear Connector indicates there's a connection, except the .onopen event is never fired. If I check the readyState I get a value of 0, indicating the connection has not yet been established. I think it's because in order to get one I have to send an authorization request first, which will be in the form of the appName & appKey, for example this:
{"appName":"Brainwave Test","appKey":"0139ccebc1902e0905b11bebc63c82eecada5784"}
The problem though is how to send an authorization request? Anyone have any ideas how to do this?

If you're not wedded to the idea of using the ThinkGear Connector driver, you can connect directly to the Bluetooth headset using the (Java) mindwave-bluetooth library, register a listener for each event type, and push a WebSocket message out for each event. That's not quite what you're asking for, but it's an option in lieu of a full WebSocket-to-ThinkGear Connector solution.

Related

In Firefox/Chrome devtools Is there a way to send/edit websocket messages after connection

I have a Safari/Firefox/Chrome browser. My browser has devtools.
Is there a way to happy send/edit websocket messages for existing connection?
Or by plugin?
Thank you
You can grab instance of websocket connection and can use it further to send further messages on it.
Grab socket connection instance
You must be aware of websocket connection establishment as below:
websocket = new WebSocket('your-ws-url-goes-here');
Now you can use instance of websocket and can use .send() and .close().
Your question states that you want to use existing connected web socket, you can look for socket connection instance in source code and can use it for sending further messages.
Example to play with
You can play with websocket and its instance here at http://websocket.org/echo.html
Notice here
var wsUri = "wss://echo.websocket.org/";
and function having
websocket = new WebSocket(wsUri);
You so you know websocket is connected and having instance in websocket
You can open devtool and type websocket to see all of the option. So in your case you need to find instance of connection so you can play with it.
About editing existing message
I couldn't find if there is any way to edit sent messages, and i think it should not be there. You can send new message since earlier message must have been responded already.
You can list all WebSocket connections on page in Chrome by opening a console and writing queryObjects(WebSocket). It should list all instances after a while.
Then choose the one you want to use and right-click on it and choose "Store object as global variable".
This will create a new variable like temp1 so you can send messages with temp1.send({websocket: 'message'}).

C# WebRequest to a URL that is configured for Windows Authentication

I am trying to get user photos out of Microsoft Exchange using the GetUserPhoto REST request documented here: https://msdn.microsoft.com/en-us/library/office/jj190905%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396
My problem is no matter what I do the connection gets closed automatically and it can't authenticate using NTLM. Microsoft even provides code but when you run this in a IIS web application even if it is using an application pool running as a domain user, it never can authenticate.
This is my current code that isn't working:
request = System.Net.WebRequest.Create($"https://{Settings.ExchangeServer}/ews/exchange.asmx/s/GetUserPhoto?email={primarySmtpAddress}&size=HR240x240") as System.Net.HttpWebRequest;
request.ServerCertificateValidationCallback = delegate { return true; };
request.UseDefaultCredentials = true;
resp = request.GetResponse() as System.Net.HttpWebResponse;
Now I can put this in a console application and run it and then it works. But in IIS it just won't work at all. I've even tried RestSharp with no luck.
Sounds like a delegation issue eg the credentials your impersonating can only be used to access resources local to the IIS server they are being impersonated on. For you to access Exchange you need to have delegation configured correctly see https://blogs.msdn.microsoft.com/emeamsgdev/2012/11/05/ews-from-a-web-application-using-windows-authentication-and-impersonation/
The problem was it wasn't trying to connect with TLS 1.2. Once it clicked in my head, the error message was saying the connection closed and not actually returning a 401. I user ServiceManager to set it to TLS1.2 and then it started working.
Glen Scales help point me in the right direction though to troubleshoot it further.

Chrome Extension, messaging: getting port status

I am trying to get a port's status in an application (not a content script). When I do :
this.port = chrome.runtime.connect("okcbadfdlhldjgkbafhnkcpofabckgde");
I get a valid port object but I can't find anyway to determine if the port can be used at all (I don't even get a disconnect event if the extension can't be reached).
The only way I figured out to have the connectivity state is to actually trap an exception when performing a this.port.postMessage.
Is there a better way ?
https://developer.chrome.com/extensions/runtime#method-connect
Update
Running Version 48.0.2564.97 (64-bit) on Linux Ubuntu
No cross-extension messaging, just application to/from extension
Extension source code but note I have since moved on to implement another strategy for the extension because of the issue raised in this question.
Your extension uses a background-script that provides listener function for the chrome.runtime.onMessageExternal event. This event is used to listen for incoming messages, send from external webpage-scripts (or other extensions) by calling the chrome.runtime.sendMessage method.
Since your extension does not provide a listener function for the chrome.runtime.onConnectExternal event, chrome.runtime.connect cannot work for your extension.
As far as knowing the connection status is concerned, in this case a simple try-catch block would do enough to know whether the extension supports port or not. If it does, you need to view the manifest corresponding to this extension - to see if a particular host is allowed to send messages or not.
I was able to send message to your extension (see the enclosed figure) by adding the following lines of code in the background-script. In addition to this, I also added the matches string for the host - www.example.org in the manifest.
chrome.runtime.onMessageExternal.addListener(
function(request, _sender, sendResponse) {
console.log(request);
...
}
);

Atmosphere push - Securing channels

My question regarding how to secure the channel in an Application using Atmosphere pub/sub.
I'm using Primefaces 3 & GlassFish server for this purpose.
Whenever I create a channel and subscribe to it, I can always see the WebSocket url in cleartext in the dev console/firebug in chrome (for instance). Can somebody sneak into subscribing to my channel? If yes, How can I secure my channel (SSL/Https maybe?). Or do I need to encrypt the channel name whenever I add new one.
Please let me know If I'm not clear with my query.
Thanks!!!
just use https/wss as URL instead of http/ws (make sure SSL is properly configured with GlassFish)
Thanks
-- Jeanfrancois

Starting multiple HTTP listeners on IIS using C#.NET 2.0

I have two windows services running on the same machine. Both the services uses
private HttpListener listener;
I specify the baseURL as "http://IPAddress:8080/" & "http://IPAddress:8081/" respectively for each of the services. Then I do the needful and call
listener.Start();
The first service starts successfully at 8080 port. But when I now start the 2nd service,
I get HTTPListenerException "The process cannot access the file because it is being used by another process" for listener object.
Could anybody please tell me:
1) If it is possible to start two HTTP listeners on the same IIS at two different ports.
2) If yes, how can we achecive this?
3) Is there any other way of doing this?
For your information:
I am using C#.NET 2.0 and IIS 6.0 server.
Thanks & Regards,
Hari
Doesn't HttpListener work independently from IIS? Can you stop the IIS service and see what happens?
Or maybe port 8081 is used by another program or process. I suggest to try to set the port to another number. You could open a command line and execute the "netstat" command to see if the port is used before starting your services.
(source: googlepages.com)
The HTTPListener is indeed not a part of the IIS. It's just C# code.
did you do it like this?
String[] prefixes = { "http://localhost:8280/", "http://localhost:8281/"};
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8280/");
listener.Start();
1) If it is possible to start two HTTP listeners on the same IIS at two different ports.
Yes, it is. But listeners on the IIS is not made through code, it's through the IIS administration tool, so that's probably not what you're trying to do. IIS is separate from the c# code you're attempting.
2) If yes, how can we achecive this?
Try some other port numbers (like 58080 and 58081) and try replacing "IPAddress" with "localhost". Most likely your port number is used by some other web server
3) Is there any other way of doing this?
If you're trying to serve web pages, you probably wan't to make a web application instead of making your own HTTP server
If you're doing something custom, you might want to take a look at WCF (Windows Communication Foundation), as it's the new framework for web, sockets, web services etc. and it's what MS will be using going forward
It's usually a good idea to take a quick look at this page when using port numbers...just to make sure a temp number you're trying to use isn't in use already.