开发者

callback javascript

I write a browser game (php, javascript) and I do not know how to make a callback. ne开发者_Python百科cessary that the server itself found a client and call the function (only had one)


Don't write a browsergame if you don't know the basics! Browsergames are way too complex to learn programming.

If you want to make the server notify a client about something you will need to keep a connection open (search keywords: COMET, long polling) as you cannot initiate connections from the server to clients.


For this I can suggest you using Firebase. It is a API that let you to add cloud Data management that your user clients do. You can use that communication to search for client.


If I understand your question, what you need is a socket. Since you're using PHP and Javascript, a WebSocket might be just what you're looking for. With WebSockets, the connection between the client and the server is persisted, so the server can just push data/messages to any or all of the clients connected to it at any point in time. Likewise, the any client connected to the server can push messages/data up to the server.

Here's a video that describes how it works a bit https://www.youtube.com/watch?v=oJxWhmt5m-o

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜