Re: [Vala] Libsoup websockets
- From: Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
- To: vala-list gnome org
- Subject: Re: [Vala] Libsoup websockets
- Date: Wed, 21 Sep 2016 10:29:35 -0400
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
You should try the 'ws://localhost:8080/' URI instead. It's also
necessary to run a GLib.MainLoop.
Also, you don't need to bind a socket manually if you only want to
listen on the loopback interface, 'listen_local' does that already.
Here's a fully working example:
using GLib;
using Soup;
var 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_local(8080, 0);
new MainLoop ().run ();
Then connect to 'ws://localhost:8080/'.
--
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]