错误conexion vue套接字ERR_CONNECTION_REFUSED

时间:2018-12-16 21:51:50

标签: node.js vue.js socket.io

我还没有设法将vue js连接到我的nodejs服务器。服务器端的配置如下:

final int intBoardSize = 5;
boolean[][] boolLightState = new boolean[intBoardSize][intBoardSize];

public void boardRandomize() {


    for (int row = 0; row < intBoardSize; row++)
        for (int column = 0; column < intBoardSize; column++)
            boolLightState[row][column] = false;

    int randomRow, randomColumn;

    for (int randomCount = 0; randomCount <= 50; randomCount++) {
        randomRow = (int) (Math.random() * intBoardSize);
        randomColumn = (int) (Math.random() * intBoardSize);
        toggleLight(randomRow, randomColumn);
    }

}

public void mouseToggleLight (int x, int y) {

    for (int row = 0; row < intBoardSize; row++)
        for (int column = 0; column < intBoardSize; column++)
            if ((Math.sqrt (Math.pow ((y - intLightPosition [1][row][column] - intLightRadius), 2) + Math.pow((x - intLightPosition [0][row][column] - intLightRadius), 2))) < intLightRadius)
                toggleAdjacentLights(row, column);

}

public void toggleAdjacentLights(int row, int column) {

    toggleLight(row, column);

    if (row + 1 >= 0 && row + 1 < intBoardSize)
        toggleLight(row + 1, column);

    if (row - 1 >= 0 && row - 1 < intBoardSize)
        toggleLight(row - 1, column);

    if (column + 1 >= 0 && column + 1 < intBoardSize)
        toggleLight(row, column + 1);

    if (column - 1 >= 0 && column - 1 < intBoardSize)
        toggleLight(row, column - 1);

}

public void toggleLight(int row, int column) {

    if (boolLightState[row][column] == false) 
        boolLightState[row][column] = true;
    else
        boolLightState[row][column] = false;

    repaint();

}

在客户端:

const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);

app.use(express.static(__dirname + '/dist'));

app.set('port', process.env.PORT || 5050);

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname + '/dist/index.html'));
});

server.listen(app.get('port'), () => console.log(`http://localhost:${app.get('port')}`));

当我在本地测试一切正常时,套接字打开的事件发出而没有失败,问题出在我上传服务器时,不断出现错误:

  

vue-socketio.js:1 GET Vue.use(new VueSocketio({ debug: true, connection: 'http://localhost:5050' })); net :: ERR_CONNECTION_REFUSED

尝试放置服务器提供商的IP仍然是问题,我已经看到了很多与此有关的问题,但是我没有一个明确的解决方案,我感谢他们能为我提供帮助,谢谢!

0 个答案:

没有答案