'Unity game Socket connection bug on EC2
I am developinng multiplayer Unity3d game using socket.io and it works well on localhost, heroku. But it seems not to work after deploying the backend code on AWS EC2.
Here is unity Code.
public void ConnectWithSocketServer()
{
if (socket == null)
{
socket = SocketIo.establishSocketConnection(ws://domain.com/);
socket.connect();
if (!isListerCreated)
{
Debug.Log("<===== Creating Socket Listener =====>");
ListenSocket();
}
isListerCreated = true;
}
}
This is app.js server code.
const server = require('http').createServer(app);
const io = require("socket.io")(server, {
cors: {
origin: '*',
credentials: true,
allowedHeaders: ["content-type"],
},
transports: ['websocket'],
secure: true,
allowUpgrades: false,
pingTimeout: 600000,
// pingInterval: 300000
});
server.listen(process.env.PORT || 5000, () => {
console.log('Server is up and running on port ' + (process.env.PORT || 5000));
});
const socketEvemts = require('./socketEvents');
socketEvemts(io);
This is socketEvents.js code
exports = module.exports = function(io) {
var players = {};
//Set Listener
io.on('connection', (socket)=> {
console.log('a user has connected');
socket.on("ping", (data) => {
console.log("Pong Time ===>", data);
socket.emit("pong", "result");
})
....
});
Please help me to solve this problem.
For socket.io, Nothing to display when I used console.log .
But API works well.

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
