I have deployed my code with docker image and here is the code for the socket connection.
I got SUCCESSFUL connection in the local system but when I deploy the same code on EC2 it gives me the following error:
I'm using express server.
Server:
var serverIO = require('http').Server(app);
var io = require('socket.io')(serverIO);
io.on('connection', function(client) {
console.log('Client connected...', client.id);
})
var server = serverIO.listen(config.app.port, function(){
console.log('server running on port:', config.app.port)
})
Client:
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<h1>Hello World!</h1>
<div id="future"></div>
<form id="form" id="chat_form">
<input id="chat_input" type="text">
<input type="submit" value="Send">
</form>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.dev.js"></script>
</body>
</html>
<script>
// var socket = io.connect('http://127.0.0.1:8000'); //here I got connection
var socket = io.connect('https://liveURL:8000'); //here I got error
socket.on('connect', function(data) {
socket.emit('join', {email: "user1@example.com"});
});
socket.on('broad', function(data) {
console.log(data)
$('#future').append(data+ "<br/>");
});
socket.on("new_msg", function(data) {
console.log("here")
alert(data.msg);
})
$('form').submit(function(e){
e.preventDefault();
var message = $('#chat_input').val();
socket.emit('messages', {email: "user1@example.com"});
});
</script>