Re: [Vala] Libsoup websockets



In general, with GIO, you don't need to run anything in a subprocess.
Keeping it single-threaded and let async I/O dictate your concurrence
model.

One really nice way to scale on multi-core is to notably use
subprocesses through fork. Once you listen, you can fork before
launching loops.

    server.listen_local (8080);

    Posix.fork (); // 2
    Posix.fork (); // 4
    Posix.fork (); // 8 process

    new MainLoop ().run ();

They now all share a common file descriptor for the listening interface
and the kernel will perform load balancing across the workers for free.
I managed to scale an application on 64 cores this way ;) reaching
~100k req/sec this way.

Good luck,

Le mercredi 21 septembre 2016 à 15:21 +0100, Baptiste Gelez a écrit :
Hi everyone,

I'm creating a little app that should be able to communicate with
other 
processes (both sending and receiving messages). I first tried to do
it 
by launching child processes and sending/receving messages with 
stdout/stdin. But I didn't find how to receive a signal when the
child 
process is writing on his stdout.

Then, I tried with websockets. I use the libsoup solution. This is
my 
code :

const uint16 port = 8080;

InetAddress address = new InetAddress.loopback (SocketFamily.IPV4);
InetSocketAddress inetaddress = new InetSocketAddress (address,
port);

GLib.Socket socket = new GLib.Socket (SocketFamily.IPV4, 
SocketType.STREAM, SocketProtocol.TCP);
socket.bind (inetaddress, true);
socket.listen ();

Server serv = new Server (null);
serv.add_websocket_handler (null, null, null, (server, conn, path, 
client) => {
     conn.message.connect ((type, message) => {
             // receive messages en responds ...
         });
     });
serv.listen_socket (socket, 0);

But when I try to connect to ws://localhost (with JavaScript) it
tells 
me "Firefox can't establish a connection with the server at the
address 
ws://localhost/."

Valadoc and libsoup C documentation are really poor on Websockets.
Can 
you help me to find where is the problem, and how to solve it,
please. 
Or at least, giving me some example codes of websocket servers with 
libsoup (I can't find any). Thank you.

Baptiste.
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
-- 
Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>

Étudiant au baccalauréat en Informatique à l'Université de Montréal
Chercheur boursier à l'IRIC

Mon blog: https://arteymix.github.io/
Clé PGP: B1AD6EA5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]