Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #78 - prepare separate example for express 3.0

  • Loading branch information...
commit ef57a99c396c0b52e6d51f3a6e638c548e06deda 1 parent b4f8865
@majek majek authored
View
71 examples/express-3.x/index.html
@@ -0,0 +1,71 @@
+<!doctype html>
+<html><head>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
+ <style>
+ .box {
+ width: 300px;
+ float: left;
+ margin: 0 20px 0 20px;
+ }
+ .box div, .box input {
+ border: 1px solid;
+ -moz-border-radius: 4px;
+ border-radius: 4px;
+ width: 100%;
+ padding: 0px;
+ margin: 5px;
+ }
+ .box div {
+ border-color: grey;
+ height: 300px;
+ overflow: auto;
+ }
+ .box input {
+ height: 30px;
+ }
+ h1 {
+ margin-left: 30px;
+ }
+ body {
+ background-color: #F0F0F0;
+ font-family: "Arial";
+ }
+ </style>
+</head><body lang="en">
+ <h1>SockJS Express example</h1>
+
+ <div id="first" class="box">
+ <div></div>
+ <form><input autocomplete="off" value="Type here..."></input></form>
+ </div>
+
+ <script>
+ var sockjs_url = '/echo';
+ var sockjs = new SockJS(sockjs_url);
+ $('#first input').focus();
+
+ var div = $('#first div');
+ var inp = $('#first input');
+ var form = $('#first form');
+
+ var print = function(m, p) {
+ p = (p === undefined) ? '' : JSON.stringify(p);
+ div.append($("<code>").text(m + ' ' + p));
+ div.append($("<br>"));
+ div.scrollTop(div.scrollTop()+10000);
+ };
+
+ sockjs.onopen = function() {print('[*] open', sockjs.protocol);};
+ sockjs.onmessage = function(e) {print('[.] message', e.data);};
+ sockjs.onclose = function() {print('[*] close');};
+
+ form.submit(function() {
+ print('[ ] sending', inp.val());
+ sockjs.send(inp.val());
+ inp.val('');
+ return false;
+ });
+
+ </script>
+</body></html>
View
8 examples/express-3.x/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "sockjs-express",
+ "version": "0.0.0-unreleasable",
+ "dependencies": {
+ "express": "~3*",
+ "sockjs": "*"
+ }
+}
View
26 examples/express-3.x/server.js
@@ -0,0 +1,26 @@
+var express = require('express');
+var sockjs = require('sockjs');
+var http = require('http');
+
+// 1. Echo sockjs server
+var sockjs_opts = {sockjs_url: "http://cdn.sockjs.org/sockjs-0.3.min.js"};
+
+var sockjs_echo = sockjs.createServer(sockjs_opts);
+sockjs_echo.on('connection', function(conn) {
+ conn.on('data', function(message) {
+ conn.write(message);
+ });
+});
+
+// 2. Express server
+var app = express(); /* express.createServer will not work here */
+var server = http.createServer(app);
+
+sockjs_echo.installHandlers(server, {prefix:'/echo'});
+
+console.log(' [*] Listening on 0.0.0.0:9999' );
+server.listen(9999, '0.0.0.0');
+
+app.get('/', function (req, res) {
+ res.sendfile(__dirname + '/index.html');
+});
View
2  examples/express/package.json
@@ -2,7 +2,7 @@
"name": "sockjs-express",
"version": "0.0.0-unreleasable",
"dependencies": {
- "express": "2.5.8",
+ "express": "<3",
"sockjs": "*"
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.