[Vala] Libsoup websockets



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.


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