constructor(props) { super(props); const { dispatch } = this.props; this.socket = io('http://localhost:8888'); this.socket.emit('NEW_PLAYER', {player: this.props.player}); this.socket.on('game', function(data) { dispatch({type: 'GAME_STATE', game: data.game}); }); }
start() { this.sio = io() this.sio.on('connect', this.onConnect) this.sio.on('disconnect', this.onDisconnect) this.sio.on('data', this.onRecv) }
describe('Successful connection', () => { it('Should emit connected', (done) => { const socket = io(`${socketURL}?browserId=someBrowserId`); socket.on('connected', (data) => { expect(data.message).to.equal('connected'); socket.disconnect(); done(); }); }); });
componentWillMount() { this.socket = io('http://localhost:3001'); this.socket.on('connect', this.connect); this.socket.on('disconnect', this.disconnected); this.socket.on('joined', this.joined); this.socket.on('audience', this.updateAudience); this.socket.on('end', this.updateState); this.socket.on('welcome', this.updateState); this.socket.on('start', this.start); this.socket.on('ask', this.ask); this.socket.on('results', this.updateResults); }
function buildConnection(uri) { let result = io(urlConnection+ uri, {'force new connection': true}); result.on('error', function () { should.not.exist("Connection error"); }); result.shouldNotAlert = function () { result.on('alert', function (msg) { result.close(true); should.not.exist(msg); }); return result; }; return result; }
$.users[v.api]=e.user $.users[v.api].info=v $.users[v.api].ws=io(v.host) $.users[v.api].ws.on('ping', function(d){ $.users[v.api].ws.emit('pong',{beat:1});
describe('Socketio Events', () => { beforeEach((done) => { ioOptions.extraHeaders['X-Real-Ip'] = '192.168.0.2'; client = io(`http://localhost:${config.node.port}/`, ioOptions); done(); }); afterEach((done) => { client.disconnect(); done(); }); describe('Connection', () => { it('Broadcasts add-ip event', (done) => { const otherIp = '192.168.0.3'; client.on('add-ip', (ip) => { expect(ip).to.be.a('number'); done(); }); setTimeout(() => { ioOptions.extraHeaders['X-Real-Ip'] = otherIp; const otherClient = io(`http://localhost:${config.node.port}/`, ioOptions); setTimeout(() => { otherClient.disconnect(); }, 3000); }, 10000); }); }); });
}, _opts) const socket = io(`http://${address}:${opts.port}`) const em = new Emitter() const api = {
var socket = io('http://' + window.location.hostname + ':8081', { 'forceNew': true, upgrade: false,
_this._pubSocket = null; _this._pubSocket = io(_this._worker.host, _this._conf.socketIO); _this._pubSocket.emit('auth', _this._conf.jwt, function (response) { if (!_this._isCorrectReponse(response, reject)) {
getMessages(socketUrl, mode) { let observable = new Observable(observer => { this.socket = io(socketUrl) console.log('socketUrl', socketUrl) if (mode === 'MESSAGE' || mode === 'ALL') { this.socket.on('MESSAGE', (data) => { observer.next(data) }) } if (mode === 'SERVER_MODE' || mode === 'ALL') { this.socket.on('SERVER_MODE', (data) => { observer.next(data) }) } if (mode === 'SERVER_MESSAGES' || mode === 'ALL') { this.socket.on('SERVER_MESSAGE', (data) => { observer.next(data) }) } return () => { this.socket.disconnect() } }) return observable }
const ws = io(endpoint) wsc.configure(auth(authOptions)) wsc.configure(socketio(ws, {
// FXCM REST API requires socket.io connection to be open for requests to be processed // id of this connection is part of the Bearer authorization var authenticate = (token) => { socket = io(trading_api_proto + '://' + trading_api_host + ':' + trading_api_port, { query: querystring.stringify({ access_token: token }) }); // fired when socket.io connects with no errors socket.on('connect', () => { console.log('Socket.IO session has been opened: ', socket.id); request_headers.Authorization = 'Bearer ' + socket.id + token; }); // fired when socket.io cannot connect (network errors) socket.on('connect_error', (error) => { console.log('Socket.IO session connect error: ', error); }); // fired when socket.io cannot connect (login errors) socket.on('error', (error) => { console.log('Socket.IO session error: ', error); }); // fired when socket.io disconnects from the server socket.on('disconnect', () => { console.log('Socket disconnected, terminating client.'); process.exit(-1); }); }
this.socket = io(this.endPointConfig);