Code Monkey home page Code Monkey logo

Comments (3)

boazsegev avatar boazsegev commented on May 23, 2024

Hi @SteMMo33 ,

I'm sorry for the late response, I'm on vacation and don't have access to my computer on a regular basis.

I think I see the problem, but I'm not not sure... I don't know what example you are pointing to, but it could be that the example uses the 0.5.x version API instead of the 0.6.x version API.

In the new API please use the facil_attach function to connect the uuid to the protocol_s object.

Please note that the facil_attach function should be called within the .on_open callback.

If you have any more questions, please let me know. I'll answer as soon as I can.

Kindly,
Bo.

from facil.io.

SteMMo33 avatar SteMMo33 commented on May 23, 2024

Hi Bo,
thanks a lot for your reply.
The example is the basic echo server.
I added the facil_attach function and now the app is alive.
I'd like to handle some websocket messages sent by a browser. If I open the connection from a browser the following is the output to the console (I've added some debug fprintfs):

mora@ubuntu-virtualbox:~/Desktop/Socket/facil.io$ LD_LIBRARY_PATH=. ./ioServer 
* Listening on port 7681
onProtStart
Server is running 1 worker X 10 threads, press ^C to stop
* Detected capacity: 4096 open file limit
* Root pid: 4736
New connection 0x7f0238000b20 for socket UUID 0x801
protOnReady 0x7f0238000b20 0x801
protOnReady 0x7f0238000b20 0x801
data 0x7f0238000b20 0x801:
<Echo: GET / HTTP/1.1
Host: 127.0.0.1:7681
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: null
Sec-WebSocket-Protocol: lws-minimal
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: BOw0PlOXkfSD4ZSiDzBxqA==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

>
protOnReady 0x7f0238000b20 0x801
protOnReady 0x7f0238000b20 0x801
Freed Echo protocol at 0x7f0238000b20

In my understanding the library shoud handle the initial autentication for the websocket, is it?
I'd like to handle only the hi-level messages between server and browser.
Is it possible with your library??
what is the purpose of the onReady callback ?

thanks again,
regards :)

PS: RedSox #1 :))

from facil.io.

boazsegev avatar boazsegev commented on May 23, 2024

@SteMMo33 Hello,

Yes, the example code you chose is from the core module (included through facil.h). The example uses plain TCP/IP sockets (without the extra WebSocket protocol).

The WebSocket protocol is part of the HTTP and WebSockets module, which you can use by including the http.h header.

A WebSockets example should available on the Website.

Like many of the examples, the API in the example is dependent on the release version.

I believe the API on the website reflects the latest 0.6.x release, but it might be updated soon to use the master branch (the upcoming 0.7.0 release API) which includes some changes to the pub/sub logic and API.

As for the on_ready callback:

The on_ready callback is "called when the socket is ready to be written to". Which basically means that once the user buffer is empty and the kernel's socket buffer has some empty space (all the previous calls to sock_write are done writing to the socket's outgoing buffer), the callback is called.

The callback behaves the same with WebSocket connections, which use websocket_write to "pack" and send the data using the WebSocket protocol.

You don't have to use it.

Bo.

from facil.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.