WebSocket versions and backwards compatibility - javascript

I've been experimenting with WebSockets for the past couple of days and I'm having some mixed experiences with the new, very cool, technology. I've written a simple chat client that uses the latest release from HTML5 Labs, which I believe is the hybi-09 draft spec release. The client works great in Chrome (dev channel v14.0). Everything functions as it should. However, in every other major browser that natively supports WebSockets (FireFox (v6.0b) (Yes, I did turn on WebSockets functionality), Safari (v5.1)), it can't connect for some reason. Here's some of my client code:
$(document).ready(connect);
function connect() {
if ('WebSocket' in window) {
websocket = new WebSocket('ws://' + window.location.hostname + ':4502/chat');
}
else if ('MozWebSocket' in window) {
websocket = new MozWebSocket('ws://' + window.location.hostname + ':4502/chat');
}
else {
//not supported
return;
}
websocket.onopen = function () {
//do some setup stuff
};
websocket.onclose = function () {
//DOH
};
websocket.onmessage = function (e) {
//Do some stuff with e.data
};
}
and some (C#) server code:
static void Main(string[] args)
{
var host = new WebSocketsHost<ReverseService>();
host.AddWebSocketsEndpoint("ws://" + Environment.MachineName + ":4502/chat");
host.Open();
Console.ReadLine();
}
Like I said, it connects fine in Chrome and hits the .onopen function as it should. In FF and Safari, it goes straight to the onclose function and never connects. In FF, I get the following errors:
"NetworkError: 501 Not Implemented - http://localhost:4502/chat"
Firefox can't establish a connection to the server at ws://localhost:4502/chat
And in Safari:
WebSocket frame (at 4294967295 bytes) is too long.
The only thing I can think of is some kind of backwards compatibility issue. I believe Chrome 14.x implements the draft 10 spec of hybi WebSockets and I think FF 6 implements draft 07 or 08 and I'm not sure about Safari 5.1. If anyone has any insight as to what the problem is and/or how/if I can fix it, I'd appreciate the help. Thanks!

Chrome 14 and Firefox 7 (Aurora build, prefixed with "Moz" but enabled by default) support the HyBi-10 version of the protocol. Everything else that has native WebSockets support is still using the Hixie-76 version of the protocol.
There are server implementations that already support the HyBi protocol and many more will soon now that Chrome 14 has it natively. There are some that have support for both Hixie-76 and the newer HyBi versions of the protocol (libwebsockets, websockify). I'm not particularly surprised that Microsoft's prototype server implementation only supports one version of the protocol (since they were not in the game during the Hixie period).
Update:
Some server options:
libwebsockets - C implementation
websockify - My python implementation. websockify is a websockets to TCP socket proxy/bridge, but websocket.py is a generic websocket module.

Here is a .NET based (free) WebSocketServer that supports Hybi10 and the older protocols. Can be found at http://xsockets.net
or run the add to your project (MVC3) by using Install-Package XSockets in the Package Manager Console in Visual Studio 2010 ( Also think the 2008 will do Nuget now)
I uses one of the videos as help http://xsockets.net/Video/Index

Here is a WebSockets protocol test report listing conformance of Chrome 14 and Firefox 7/8 to specific features of the latest protocol spec.
The test suite is part of Autobahn WebSockets, a little project of mine that includes Python/Twisted-based WebSockets implementation, which can be used to write clients and servers.
Code is Apache 2.0 licensed and all on GitHub.

Related

detect internet connection type in uwp allication?

I am developing a uwp application that builds to windows store and xbox basically.
My code is like
var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
var networkType=null;
var interfaceType = profile.NetworkAdapter.IanaInterfaceType;
// 71 is WiFi & 6 is Ethernet
if (interfaceType == 71)
{
networkType="wifi";
}
else if (interfaceType == 6)
{
networkType="ethernet";
}
when i was connected to wifi and run this code in xbox i am getting the connection type as "ethernet", but when i run the same code on my local machine i am getting the value as wifi.
Any helps appreciated:)
Since you are using the NetworkAdapter class, if you check the device family of this class:
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
For Xbox, we need to check the UWP features not yet supported on Xbox, and NetworkInformation is in "Feature areas less applicable to Xbox" section.
NetworkUsage, ConnectivityInterval, NetworkInformation, and DataPlanStatus APIs are not supported on Xbox.
So it seems like it is currently not completely supported.

UPnP discovery, description inside Javascript

I am looking to get UPnP device discovery, description done in Javascript - either in standalone browser environment or in NodeJS
Towards that, I tried below two solutions but both did not work for me. Details -
1]NodeJS bases:
https://www.npmjs.com/package/upnp-client
After correcting few typos in the example app, and running it in node (My nodeJS is running under X-Ubuntu Virtual Machine inside Virtualbox)
I get below errors on running the upnp-client example app
dgram.js:399
throw new errnoException(process._errno, 'addMembership');
^
Error: addMembership EBADF
at new errnoException (dgram.js:457:11)
NodeJS version: v0.10.25
Upnp client api: 0.0.1
2]Under Browser(Chrome/IE)
https://www.npmjs.com/package/upnp-client
None of them at the versions I have supported the navigator.getNetworkServices API which seems to be needed for this library
How can i get UPnP device discovery working in Javascript?
Any other solutions or pointers to resolve above errors/workarounds appreciated.
UPnP uses TCP/UDP packages for advertisement/discovery/etc. And since browsers cannot open network sockets, the short answer is: No. We can't use UPnP in a browser at the moment.
The only glimmer of hope is the Network Service Discovery, which is still in development phase in most of the browsers. In Chrome for example you could enable it using chrome://flags/#enable-experimental-web-platform-features, and then would be able to do something like this (from W3C draft):
function showServices( services ) {
// Show a list of all the services provided to the web page
for(var i = 0, l = services.length; i < l; i++) console.log( services[i].name );
}
navigator.getNetworkServices('zeroconf:_boxee-jsonrpc._tcp').then(showServices);

RTCIceCandidate instance cannot be created in browsers on moblie devices

I'm recently trying some awesome features of HTML5 and WebRTC, and am building a site to allow multiple people video chat.
Everything works just fine on my PC and the Media Capture of HTML5 works like a charm. But when I set up a video source on my PC, and try to connect to it via my android/iphone/ipad, it just did not work. I checked the logs, it suggests that the creation of RTCIceCandidate failed for some unknown reason:
// To be processed as either Client or Server
case "CANDIDATE":
trace("************important*********", "we get in");
var candidate = new RTCIceCandidate({candidate: msg.candidate});
trace("************important*********", JSON.stringify(candidate));
break;
turns out the second log never shows up.
Anyone has any idea? Is is because such features are not available on mobile devices for now? Or should I do something specially for mobile devices?
oh and this is the callback of IceCandidatem which is never called:
// This function sends candidates to the remote peer, via the node server
var onIceCandidate = function(event) {
if (event.candidate) {
trace("openChannel","Sending ICE candidate to remote peer : " + event.candidate.candidate);
var msgCANDIDATE = {};
msgCANDIDATE.msg_type = 'CANDIDATE';
msgCANDIDATE.candidate = event.candidate.candidate;
msgCANDIDATE.peer = server;
msgCANDIDATE.me = weAreActingAs;
//trace("openChannel","candidate peer : " + JSON.stringify(event));
socket.send(JSON.stringify(msgCANDIDATE));
} else {
trace("onIceCandidate","End of candidates");
}
}
The server is in nodejs.
Thanks so much guys! Need your hands!
You should be able to test device support here: http://www.simpl.info/getusermedia/
I'm no expert on webrtc but according to the following site there should be supported for IOS and Android: http://updates.html5rocks.com/2012/12/WebRTC-hits-Firefox-Android-and-iOS but you'll need to use the ericsson browser
In one of the comments it does say that ericsson browser uses the depreciated ROAP signaling and can't be used in peer communication with (for example) Chrome. One comment states that blackbarry native browser now supports getUserMedia so maybe Android and iOS will follow. No native support at the moment though. And ericsson browser implementation seems to be based on depreciated standards.

are websockets not supported in Firefox 19?

i am trying to write a websocket page, and it works in Chrome and some other browsers on my Ubuntu machine.
however, firefox would not run the websocket part, and both window[WebSocket] and window[MozWebSocket] return "undefined". does firefox not support websockets?
Use (from MDN docs):
var mySocket = new WebSocket("ws://www.example.com/socketserver", "protocol");
It is supported from Firefox 6.0 (known as MozWebSocket prior to Fx 11 - see #Dracs' comment).
Extensions like TorButton can set network.websocket.enabled to false in about:config. Make sure it's true.

Windows Phone 8 IE10 Javascript debugging

IE10 has some wonderful enhancements in the HTML5 compliance area but remains a bear to develop JavaScript HTML5 when running on the WP8 as there is no way to debug the app except console messages.
Is there a remote debugging experience available for IE10 running on WP8 like the WebKit phone browsers have(see my video at http://www.youtube.com/watch?v=GNAjzFpNEj4 for example). When this is in place with a USB cable to desktop Safari debugging Javascript apps on IOS is easy as breakpoints can be set and variables examined in the remote debugger . I am hoping the same capabilities are in IE10 and would appreciate any information on where to enable these very much needed capabilities.
The bad news, that there is no new debug capabilities in comparison to WP7/IE9. Please take a look on How do I debug Internet Explorer on Windows Phone 7? since we are in exactly the same situation on WP8.
What I personally use on daily basis
Debug your app in IE10 Desktop as much as possible
Weinre remote debugger. Demo video. You can use the following app based on Weinre to simplify its usage (no local setup needed) - IeMobileDebugger src or link to Store
Supports
Html traversing
Html node styles, properties, metrics
Reading console output
Executing js on device side from console (including intellisense)
Dynamic script injection - ability to debug live sites
Not supported
js breakpoints
For javascript line by line debugging use aardwolf. Demo with VS integration.
To redirect console trace to Visual Studio output and be able to use console.log("some message") for tracing
index.html:
<script type="text/javascript">
window.console = {
log: function (str) { window.external.Notify(str); }
};
// output errors to console log
window.onerror = function (e) {
console.log("window.onerror ::" + JSON.stringify(e));
};
console.log("Installed console !");
</script>
MainPage.xaml.cs
private void Browser_Loaded(object sender, RoutedEventArgs e)
{
Browser.IsScriptEnabled = true;
// Add your URL here
Browser.Navigate(new Uri(MainUri, UriKind.Relative));
Browser.ScriptNotify += (s, arg) =>
{
Debug.WriteLine(arg.Value);
};
}
FWIW: Windows Phone 8.1 finally supports remote debugging. See http://blogs.msdn.com/b/visualstudioalm/archive/2014/04/04/diagnosing-mobile-website-issues-on-windows-phone-8-1-with-visual-studio.aspx
While not a full solution, Lauri Piispanen's consolelog.js, a nodejs-based remote JS console logger could help you.

Categories