Synchronous websocket communication

0 favourites
  • 5 posts
  • Hello,

    I am using websockets to communicate from a client with a C3 game. The communication is bi-directional and asynchronous, that is a client can send a message to C3 and C3 can send a message to a client.

    I wondering if there is a way to do synchronous messages from a client to C3 -- quite like having the C3 game act as a REST (API) server.

    e.g. suppose the client want to query the C3 as to how may sprites there currently are instantiated and receive a response immediately back.

    Can something like this be done via web-sockets or otherwise?

    Tagged:

  • You could always use the built in plugin for a peer to peer connection.

    But there is literally no such thing as instantaneous either way as far as the internet is concerned. Any and all communications are asynchronous by nature, as there is no way to know ahead of time how long it takes for any given message to be received regardless of the method.

  • Hi,

    Many thanks for your message.

    I didn't see that the multiplayer plugin supports arbitrary synchronous messages between peers ...

    re: instantaneous

    I didn't mean instantaneous, but synchronous -- this means that the client send a request to C3 to obtain some information, and then waits until the respond from C3 arrives back.

    If, possible, the client could also have a timeout mechanims - i.e. to not wait indefinitely.

    But, surely, since all this happens over the network there is latency -- i.e. it takes time.

    Edit:

    In theory, perhaps this can be accomplished by introducing a REST API plugin that treats the game as if it were a source of data on the web.

    Edit 2:

    Perhaps, the NW.js is a good example -- quite like the NW.js plugin which augments C3 with file system capabilities, a REST.js plugin would turn C3 into a web data source.

    thanks,

    Dan

  • Networking should not be handled synchronously. It just means the app will hang and become totally unresponsive for unpredictable amounts of time. Doing it asynchronously is entirely better.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you.

    In the meantime I realized that event a REST API which I erronous thought is synchronous -- is in fact most often used asynchronous -- it requires some kind of call back handing -- promises and the like.

    But, i guess, an asynchronous query API doesn't yet exist for C3 -- although, I am now thinking that i can "bend" web-sockets to this purposes, when i figure out how to implement such a call back mechanism on the client side.

    Btw, it seems that the multiplayer game offers some built-in means to request information from other games in the network - but its not a general purpose mechanism.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)