0

I have a problem w my Node Server + Socket Client. Well, my localhost server works perfect.

But... when i connect my socket.io client (node) w my external server (ex: www.myserver.com:3000) doesnt works.

I dont recieve any data. (message var)

This is my sample code:

var io = require("socket.io-client");
var requestHTTP = require("request");

  var socket = io('http://myserver.com:3000');
  var room = "game881";

  console.log('test simple socket '+room+'');

  socket.on('news', function (data) {
    console.log(data);
    socket.emit('conectado', { my: 'Conectado!' });
  });

socket.on('connect', function () {
    socket.emit('room', room);
    console.log('Conectando a ' + room);
  });

  socket.on('message', function (data) {

    var json = data.message;
    json = JSON.parse(json);
    console.log(json);

  });+

Why dont recieve any data?

CORS? I've already tried. Port used?

:) thanks!

1 Answer 1

0

Well... i solved my problem. I use this.

Setup Server-Server SSL communication using socket.io in node.js

The previous answers didn't do it for me. require('https').globalAgent is always >undefined.

Did some seaching and found the rejectUnauthorized parameter in the docs (https://nodejs.org/api/tls.html). Not sure if it's related to SocketIO, but it somehow seems to work with self-signed certificates:

var socket = io.connect('//yourhost:8000', {secure: true, rejectUnauthorized: false})

secure: true might be optional, but I like to enforce it anyhow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.