I have tested the code on localhost and it works. However, when i push it to heroku, the code does not emit event.
I am using this library for python client side: https://python-socketio.readthedocs.io/en/latest/client.html#installation
This is my code: Server: (I host this code on glitch)
onst express = require('express') // to host web server
const socketIO = require('socket.io')// to provide us the realtime communication
const cors = require('cors')
const port = process.env.PORT
// const port = process.env.PORT || 80
const app = express()
app.use(cors())
const server = require('http').createServer(app).listen(port)
const io = socketIO.listen(server,{
pingInterval: 10000,
pingTimeout: 5000,
})
io.set('origins', '*:*')
console.log('Server has started...')
app.get('/', function (req, res) {
res.sendStatus(200)
})
// Whenever a socket/user joins the server (io),
io.on('connection', (socket) => {
console.log(socket.id)
socket.on('online',()=>{
console.log('online')
//do nothing
})
socket.on('NEW_ORDER', (data,id)=>{
console.log('receive order',data)
console.log(data['order'])
})
}
Client side:(I host these code on heroku)
import socketio
sio = socketio.Client()
@hawker_centers_blueprint.route('/payment_successful', methods=['POST'])
def pymt_succesful():
print('connected to socket', sio.sid) #this shows on heroku log and i can know the socket's id
sio.emit('online')#this does not show on server side's log
sio.emit('NEW_ORDER',{'order':order, 'eatery_id':order['eatery_id']}) #This does not show on server side's log
print('emit order')# this shows on heroku's log
sio.connect('https://magenta-buttery-silver.glitch.me/')
When i check the log, i know that my python client is connected to socket server.It is either the server does not react when python client emit an event or the python client does not emit an event.
Can anyone help me with this?