0

I have just started using node.js socket.io. I am working on a simple connection between client and server.

Here is my server code:

var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var socketio = require('socket.io');

var app = express();

app.set('port', process.env.PORT || 1337);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', routes.index);

var server = app.listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
var io = socketio.listen(server);

and this is the client code(http://smartican.com/nodetest.html):

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="socket.io.js"></script>
<script type="text/javascript">
var socket;
socket = io.connect("http://smartican.com:1337/");
$(function() {
 alert(socket.transport.sessionid);  
});
</script>
</head>
</html>

there seems to be a problem when connecting to the socket from client as line

socket = io.connect("http://smartican.com:1337/");

breaks the script.. I have tested and the socket is open

user3455531
  • 775
  • 1
  • 14
  • 28

1 Answers1

0

Your socket.io.js is the wrong javascript file. It's the server javascript not the client javascript. You want socket.io-client.js. Take a look at this answer.

Community
  • 1
  • 1
Ulrich Thomas Gabor
  • 6,584
  • 4
  • 27
  • 41