btford / btford/angular-socket-io
Recursive messages on server socket console when trying to connect a node client socket
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
I started a project with the generator Angular-Fullstack. I want that external Node Clients (running in other machines) can connect to socket server in the Angular-FullStack project.
I have tested it with a simple node server and client and it works fine. The code is:
**NODE SERVER:**
```
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var port = 9000;
server.listen(port, function(){
console.log('Express server listening on %d port', port);
});
// __dirname is the directory where this file is placed
app.get('/', function (req, res) {
res.sendFile(__dirname + '/browserSocketAppClient.html');
});
io.on('connection', function (socket) {
console.log( 'THE SOCKET: ' + socket.toString());
socket.emit('NODE SOCKET SERVER', { SERVER: 'NODE SOCKET SERVER' });
socket.on('NODE SOCKET CLIENT', function (data) {
console.log(data);
});
});
```
**NODE CLIENT:**
```
var io = require('socket.io-client');
var socket = io.connect('http://192.168.0.101:9000');
socket.on('connect', function() {
console.log( 'NODE SOCKET CLIENT has connected with the server');
});
socket.on('NODE SOCKET SERVER', function (data) {
console.log(data);
socket.emit('NODE SOCKET CLIENT', { CLIENT: 'NODE SOCKET CLIENT' });
});
```
**THE SERVER CONSOLE:**
```
D:\003_IOT\CODE_EXAMPLES\TestSocketIO>node nodeSocketServer
Express server listening on 9000 port
{ CLIENT: 'NODE SOCKET CLIENT' }
```
**THE CLIENT CONSOLE**
```
D:\003_IOT\CODE_EXAMPLES\TestSocketIO>node nodeSocketClient
NODE SOCKET CLIENT has connected with the server
{ SERVER: 'NODE SOCKET SERVER' }
```
But when I want to use the same NODE CLIENT: with the Angular-Fullstack project, it doesn't work.
I have added this code to myproject/server/config/socketio.js
**socketio.js**
```
function onConnect(socket) {
socket.emit('NODE SOCKET SERVER', { SERVER: 'You are connected with NODE SOCKET SERVER' });
socket.on('NODE SOCKET CLIENT', function (data) {
console.log(data);
});
............................
}
```
And I get in the **console of the server** this recursive message,
```
Express server listening on NaN : 9000 in development mode
finished populating users
GET /socket.io/?EIO=3&transport=polling&t=1438187488692-7 200 27ms
[undefined:undefined] SOCKET CONNECTED
GET /socket.io/?EIO=3&transport=polling&t=1438187489437-306 200 9ms
GET /socket.io/?EIO=3&transport=polling&t=1438187493792-8 200 8ms
GET /socket.io/?EIO=3&transport=polling&t=1438187495438-307 200 5ms
GET /socket.io/?EIO=3&transport=polling&t=1438187498815-9 200 4ms
GET /socket.io/?EIO=3&transport=polling&t=1438187501438-308 200 5ms
GET /socket.io/?EIO=3&transport=polling&t=1438187503827-10 200 7ms
```
But it never really connects.
It has to be something in the configuration in the server side of the Angular-Fullstack project, but I can't fid it.
Any Idea Thanks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.