Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Looking for tips on development with websockets in Windows

Hello everyone. I'm started messing around with node.js and am trying to setup a basic web socket app. I've installed node.js for Windows, WAMP, and am using the node websocket lib. When I run 'node server.js' and is successful and when I connect to  'localhost/client/index.htm' in a webbrowser the server console acknowledges there was a connection and gives the connection ID but in the developer tools of the browser (Chrome) I get the error:


Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing :1
WebSocket connection closed.
In Firefox I get:

Error: Firefox can't establish a connection to the server at ws://
Source File: http://localhost/client/js/html5games.websocket.js
Line: 9

the html5games.websocket.js code is 
var websocketGame = {
// init script when the DOM is ready.

// check if existence of WebSockets in browser
if (window["WebSocket"]) {
// create connection
websocketGame.socket = new WebSocket("ws://");
// on open event
websocketGame.socket.onopen = function(e) {
console.log('WebSocket connection established.');
// on message event
websocketGame.socket.onmessage = function(e) {
// on close event
websocketGame.socket.onclose = function(e) {
console.log('WebSocket connection closed.');


 the client index.htm is:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>WebSockets demo for HTML5 Games Development: A
Beginner's Guide</title>
<meta name="description" content="This is a WebSockets demo
for the book HTML5 Games Development: A Beginner's Guide
by Makzan">
<meta name="author" content="Makzan">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/html5games.websocket.js"></script>

 And finally the server.js

var ws = require(__dirname + '/lib/ws/server');
var server = ws.createServer();
var totalConnectedClients = server.manager.length;

server.addListener("connection", function(conn){
// init stuff on connection
console.log("A connection established with id",conn.id);
var message = "Welcome "+conn.id+" joining the party. Total connection:"+server.manager.length;
console.log("WebSocket server is running.");
console.log("Listening to port 8000.");

var message = "a message from server";

 I have no idea why the client/server hsndshake won't complete, the server acknowledges a connection but immediately drops it, but the client file's debug says it couldn't connect. What's going on here?

Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Looking for tips on development with websockets in Windows

This doc may be old, but does have a clear description of each of the different client/server pieces. 




Looking at your code snippet, I don't see the data or close events in your server.js file.  Could adding a listener for ondata help get where you want to be?

Follow me on Twitter: @n_adam_stanley
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Looking for tips on development with websockets in Windows

Thanks for that site. Will try what you suggested and let you know.