문제

Is there any way to get a "handle" (e.g. a Pid) to a client when using the handle_message/1 callback? so I can send messages to specific clients, and spawn processes with a list of clients as argument (e.g. for a game/chat session) for a specific group of clients.

Or is there any other way I should solve this with Yaws? I haven't found it in any documentation or example on the Yaws website.

도움이 되었습니까?

해결책

In your out/1 function where you return {websocket, CallbackModule, Options} to upgrade your connection to WebSocket, you can set the Options value to indicate that your callback module is an advanced callback module, which lets you also specify an initial state value that's handed to your callback module each time Yaws calls it. If there's client-specific information sent in the initial HTTP request, your out/1 function will receive that info in its #arg{} argument, so you can retrieve it from there and return it as part of your initial state.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top