You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to determine when a client connects and disconnects, but I'm not seeing a clear way. I was thinking of adding on some extra opcodes, but I'm seeing an opcode that isn't clearly showing up in the source code.
When a client connects, I get opcode of 16 and a message of the ip address.
When a client disconnects, no message or opcode is being picked up.
Am I missing something or is this not currently a feature? Additionally, where is opcode 16 coming from?
Just to clarify your question a bit, are you aiming to handle the onopen, onmessage, and onclose events on your side, or are you specifically referring to using the enum WSOPCODE defined in the API?
Yes. I was wanting my program to know when a user connects or disconnects. In my case, I would pair the listener with a user login in a database if the user provides a username/password after connecting. If the user disconnects, it would unpair the listener.
In websocket.c has WSOpcode defined and it has 0, 1, 2, 3, 8, 9 and 10 defined. gwsocket.c has ptr += pack_uint32 (ptr, 0x10);. Which is 16, but it's not clear that this code indicates an on connect event.
Activity
bit-garden commentedon Sep 3, 2025
I think I figured it out.
In your examples, you have an early return when the length of the payload is 0.
Perhaps illustrating the extra op codes or at least how to see if a client connects/disconnects in your examples might help.
allinurl commentedon Sep 5, 2025
Just to clarify your question a bit, are you aiming to handle the onopen, onmessage, and onclose events on your side, or are you specifically referring to using the
enum WSOPCODEdefined in the API?bit-garden commentedon Sep 5, 2025
Yes. I was wanting my program to know when a user connects or disconnects. In my case, I would pair the listener with a user login in a database if the user provides a username/password after connecting. If the user disconnects, it would unpair the listener.
In websocket.c has
WSOpcodedefined and it has 0, 1, 2, 3, 8, 9 and 10 defined.gwsocket.c has
ptr += pack_uint32 (ptr, 0x10);. Which is 16, but it's not clear that this code indicates an on connect event.I found this while trying to figure out why your example codes did not print out disconnect messages initially.
My full working example is something like this.
allinurl commentedon Sep 5, 2025
I see. It looks like you can simply pass your callback when instantiating the server. For example, here's how the onopen is done in goaccess.
The server struct provides three options you can use.