I need to create a communication via socket between a javascript application (client) and a julia application (server).
I searched the forum and didn’t find something that works, can someone help me with an example that works?
# server written in Julia
using Sockets
@async begin
server = listen(ip"127.0.0.1", 2812)
while true
sock = accept(server)
@async while isopen(sock)
write(sock, "echo: " * readline(sock) * "\n")
end
end
end
# client written in JavaScript - Not work
const WebSocket = require('ws');
const ws = new WebSocket('ws://127.0.0.1:2812')
ws.on("connection", () => {
console.log("Connected")
});
ws.addEventListener('message', message => {
console.log(message)
})
ws.onopen = function(e) {
console.log('open')
};
ws.onmessage = function(data) {
console.log(data);
}
ws.send('abc');
My question is that I need to develop the real-time system (back-end and front-end) in which the back-end will be developed in julia and the front-end in javascript, communication via websocket, I put the example code in the first post.