Wednesday 15 June 2011

javascript - socket io client net::ERR_CONNECTION_REFUSED -


I am currently creating a todo application with real time notifications

CONTEXT I PHP (Laravel 4) with frontend and angularJS (male: generator-angular). These two applications are not on the same domain (backend.herokup.com and frontend.herokup.com) Customer speaks to the server through a public API.

I want to add real time notifications to a single app, when a user wants to create a new tool, I want the UI to be updated on all the associated browsers.

The server is using the "emitter example" for PHP and server when a url of my API is killed, then the PHP customer emits an event on the NodesJS server. It is currently working, but only if the server is from a PHP server in the same domain.

Here is the configuration of the Laravel application

  + app + controller - AlertsController.php + push - server.js  

AlertsController. Php

  class AlertsController ApiController {Public function index ($ userId = null) {$ client = new Client new version 1X ('http: // localhost: 1337')); $ Customer & gt; Start (); $ Client- & gt; Eject ('broadcast', ['foo' = & gt; 'bar']); $ Customer & gt; near (); }}  

server.js

  var server = ('http') is required. CreateServer (), io = require ('socket.io') (server), logger = required ('Winston'), ports = 1337; // logger config logger Revov (Logger Transports Console); Logger.add (logger.transports.Console, {colorize: true, timestamp: true}); Logger.info ('SocketIO & gt; listen on port' + port); Io.on ('connection', function (socket) {var nb = 0; logger.info ('SocketIO & gt; connect socket' + socket.id); socket.on ('broadcast', function (message) {+ + Nb; console.log ("broadcast!"); Logger.info ('ElephantIO Broadcast & gt;' + JSON.stringify (message)); io.emit ('alert.created', JSON.stringify (message)) ;}); Socket.on ('disconnect', function () {logger.info ('socketio: received' + nb + 'message'); logger.info ('socketio> gt; disconnected socket' + socket.id );});}); Server.listen (port);  

I launch my server.js file by npm start . I am using Homestead for Laravel.

The client my client is on another application, so I imported into my bover file and included it in the project. The file is correctly imported (200 OS is fine in the network panel of Chrome Development Tools) The problem is that when I set up my io connection, I have been given "GET net :: ERR_CONNECTION_REFUSED" in the console panel.

I am using Grant to create a webserver.

Here's what I did in the client file:

  var socket = io.connect ("http://127.0.0.1:1337"); Socket.on ('alert.created', function (msg) {console.log ("created a new alert", msg);}); Do anyone know where the problem can come from? It's weird, I can have a connection between PHP and nodjs, but not between my nodejs server and my javascript client. 

OK, I came to know how my problem was solved.

I removed the nodes server from Homestead and started it out.

Everything works fine now.

Thanks guys!


No comments:

Post a Comment