clemenskresser / ezwebsocket

Simple Websocket Server Library written in C
Other
4 stars 7 forks source link

How to get client websocket end? #5

Open alexe100 opened 4 years ago

alexe100 commented 4 years ago

Hi

void onOpen(void socketUserData, void *clientDesc) { return NULL; }

onOpen I want to save the client endpoint in a hastable (one entry per client connection) but I can not find the way how to get it using the void clientDesc arg. I am getting error: dereferencing pointer to incomplete type ‘struct websocket_client_desc’ I can not simply store the clientDesc arg because it has the same address for all clients. How to access to the internal void socketClientDesc; of the struct websocket_client_desc?

Thanks a lot Alex Great piece of software!

clemenskresser commented 4 years ago

Hi Sorry for the late reply! I somehow missed the mail and haven't been here for a while

I checked what you said and changed the onOpen function in the example: void onOpen(void socketUserData, void *clientDesc) { printf("%s() clientDesc:%llx\n", func, (unsigned long long) clientDesc);

//you can return user data here which is then //passed to onMessage as userData return NULL; }

and I got the following output: onOpen() clientDesc:7f8a600008f8 onOpen() clientDesc:7f8a640008f8 onClose() onClose()

...as you can see I get different addresses for the clientDesc

So I'm not sure what you did exactly. Can you give me an example that fails?