# Communication JavaScript application (client) and a Julia application (server)

**URL:** <https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358>\
**Category:** General Usage\
**Created:** [October 6, 2022, 3:46pm UTC](https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358 "2022-10-06T15:46:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ricardo_lima/32/43312_2.png) [@Ricardo\_Lima](https://discourse.julialang.org/u/Ricardo_Lima)\
**Post date:** [October 6, 2022, 3:46pm UTC](https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358/1 "2022-10-06T15:46:51Z")

</div>

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?

```julia
# 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

```

```julia
# 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');

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 6, 2022, 4:18pm UTC](https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358/2 "2022-10-06T16:18:14Z")

</div>

Isn’t it all here? [Julia Web · GitHub](https://github.com/JuliaWeb)

Julia can work as a web server for you, for Genie.jl (or use external web server).

> [@Which async web server should I use?](https://discourse.julialang.org/t/which-async-web-server-should-i-use/38755):
>
> Hello there! I’m a Python programmer with 20+ years of programming background. I just recently read about Julia and read about 100 pages from the official documentation at once. I’m facinated by Julia’s type system, I really like multiple dispatch and many other things. At my work, I need to implement a microservice that uses async events and websockets for sending and receiving messages to/from web clients (browsers). I have some experience with tornadoweb and websockets, and could do this in…

Possibly this one helps [GitHub - wookay/Bukdu.jl: Bukdu 🌌 is a web development framework for Julia](https://github.com/wookay/Bukdu.jl) and JuliaWebAPI.jl (e.g. ZMQTransport or JSONMsgFormat?), WebSockets.jl, WebIO.jl (with example) and [GitHub - JuliaGizmos/JSExpr.jl: Translate Julia to JavaScript](https://github.com/JuliaGizmos/JSExpr.jl)

---

<div class="post-metadata">

**Author:** ![Ricardo\_Lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ricardo_lima/32/43312_2.png) [@Ricardo\_Lima](https://discourse.julialang.org/u/Ricardo_Lima)\
**Post date:** [October 6, 2022, 6:31pm UTC](https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358/3 "2022-10-06T18:31:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [October 6, 2022, 6:39pm UTC](https://discourse.julialang.org/t/communication-javascript-application-client-and-a-julia-application-server/88358/4 "2022-10-06T18:39:53Z")

</div>

> [@Ricardo\_Lima](#):
>
> ```julia
> using Sockets
> @async begin
> server = listen(ip"127.0.0.1", 2812)
> while true
> sock = accept(server)
> 
> ```

You should use a WebSocket library unless you want to implement the WebSocket protocol [RFC 6455 - The WebSocket Protocol](https://datatracker.ietf.org/doc/html/rfc6455) over a TCP socket yourself. Try [GitHub - JuliaWeb/WebSockets.jl: A WebSockets library for Julia](https://github.com/JuliaWeb/WebSockets.jl).
