-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiplayer for web client. Closes GH-12 #36
Conversation
Berkeley sockets connect() is sync, but the web is async. Emscripten APIs: http://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#socket-event-registration . library_sockfs connect: https://github.com/kripken/emscripten/blob/master/src/library_sockfs.js#L445 - bridges to websocket, always returns EINPROGRESS since its non-blocking. Asyncify? Change client to use nb sockets? http://beej.us/guide/bgnet/output/html/multipage/faq.html
Emscripten's socket tests/demos: https://github.com/kripken/emscripten/tree/master/tests/sockets |
…rotocol) This also eases proxying from websockets to the native server, for example with https://github.com/novnc/websockify: ./websockify.py 4081 localhost:4080
Progress, able to connect to a websockified server.py (using port 4081 to 4080). emscripten has some clever tricks up its sleeve, 172.19.x.x IP addresses as placeholders from gethostbyname() so the BSD socket APIs can be used to pass hostnames ("localhost") to the websocket APIs. This works, the major change vs native BSD sockets is the addition of emscripten socket callbacks. connect() returns immediately with errno=EINPROGRESS, and calls the callback set by emscripten_set_socket_open_callback() when it is ready. Instead of a worker thread to blocking recv() in a loop, using emscripten_set_socket_message_callback() to recv then parse_buffer(). The receiving code is actually simpler, no need for a queue and buffering since websockets can deliver framed messages. Some work to do handling other callbacks but it is able to connect to a server, screenshot: Looping, client_message callback reads bytes 1468, 78, 7, then logs "Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!" and client_message callback reads -1 bytes six times in a row, then client_closed callback is called.. and then back to client_opened, Logging in anonymously, and "[post-exception status] Exception thrown, see JavaScript console" but can't see it, "SimulateInfiniteLoop", then repeats client_message callbacks reading data. Infinite recursion? Stack overflow! Attempted to allocate 49152 bytes on the stack, but stack has only 31040 bytes available! The problem seems to be setting the main loop (emscripten_set_main_loop()) in the socket callback (emscripten_set_socket_open_callback()), main loop with simulate infinite loop raises exception SimulateInfiniteLoop, so the caller doesn't let code execute after it, simulating while(1);. Maybe not the right way to do this. There are other utility functions https://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html to control the main loop: pause, resume, or push blockers. Can't pause the main loop before setting it, but setting runs it infinitely. emscripten_push_main_loop_blocker()? |
Changed to however, the text console shows network messages are received and processed (player join, chat, etc). Something amiss in the main game loop after going online? |
GH-12 Multiplayer support (connecting to servers) in web version