0

I am using Daftmonk's angular-fullstack, and I want to send data through sockets TO the server. I found examples of how to receive from the server but not the other way around. The socket factory in the package doesn't seem to support any emit functions. So do I need to modify the socket service file to get that functionality or is there a better way?

SuSub
  • 73
  • 1
  • 6

1 Answers1

2

first you need to require the socket.js file in script .js

i have installed it via bower and then in the controller create an instance of the socket like

var socket = io.connect('http://localhost:4000');  

this connects the socket to server and then you can emit the events from the controller like

socket.emit("<event name>")

and listen that event on the server and you need an socket innstance attached to server if not then npm install socket and then require it and then attach it to the app

the server side is:

var server = require('http').createServer(app);      
var io = require('socket.io').listen(server);    
io.sockets.on('connection', function(socket){   console.log('a user connected');    })
server.listen(4000,function(){   console.log("The server running at port 4000"); });
Alexandru Marculescu
  • 5,569
  • 6
  • 34
  • 50
Amit Kumar
  • 407
  • 5
  • 7