So, I've been looking into online games and I was wondering how they managed to have such a fast, seemingly constant connection to the server. I've already tried just sending a bunch of XMLHttpRequests, but these tend to be slow. I've also tried researching, but most articles on the topic talk about things like web sockets, tcp and udp, concepts I don't understand at all. I'm also trying to do this all without importing code from an external source so I can better understand how it all works. Please help if you can. Thanks!
Constant connection to server online
214 Views Asked by Ghibbbeey At
1
There are 1 best solutions below
Related Questions in TCP
- Java SocketException: Connection reset,. What is the cause?
- How does a server handle multiple requests, and how does is know where to send which response?
- How does pre-allocating a pool of SocketAsyncEventArgs objects upfront improve the performance of a server application in c#
- How to peek or ready to check whether HTTP request or not in TCP proxy?
- How does bash > /dev/tcp/"ip"/"port 0<&1 keep its connection alive?
- Python TCP Server that both sends and or receives data (independently) using asyncio streams?
- Can't remotely connect to my postgresql database on digitalocean
- Why my message doesn't write into the socket when I try to read the response after sending it?
- What makes MQTT a raw tcp connection that we can't run it in the browser?
- ImGui rendering wrong characters (characters received from tcp sockets)
- TCP/IP Server Using sockets Java
- C# tcp socket keepalive I want to visit a website, but the specified time is very slow and I cannot access it
- Java TCP socket want to multiple times input with one connection
- How do I receive TCP messages on an android Emulator from a physcal device
- Getting error while using the MessagePattern to communicate between microservices
Related Questions in WEBSOCKET
- Resolving ElephantIO ServerConnectionFailureException: Error establishing connection to server
- Django socketio process
- How to decode audio stream using tornado websocket?
- Java and React WebSocket - Error Connection
- Socket.io nodejs server .NET connection
- Troubleshooting WebSocket 502 Error in Python Code
- Getting an error in Socket.io wordle project
- Best practices with realtime data / websockets. Send vs. revalidate data
- My socket.io web socket application is not sending data to some users
- Android 13 & 14 seem to close WebSocket connection, if i put app in background, after ~20s
- Audio bytes chunks getting corrupted during streaming using Django and Websockets
- Odoo live chat not working when using apache reverse proxy
- websocket Fatal error message stating "Failed to listen on tcp://0.0.0.0:8080: Address already in use
- Stomp connection using JWT token in Python
- Symphony Fintech (XTS) market-data socket data integration in PyQt6 using python3
Related Questions in UDP
- Discussion on using golang to implement UDP client timeout retransmission
- What is the correct way to setup and use the Ethernet library in Arduino in order to send and receive UDP broadcast messages between LAN devices?
- Multicast packets not received on windows
- Microcontroller hangs with LWIP UDP
- UDP socket client not able to receive data
- "Parameter is not valid" exception when using Image.FromStream() - UDP Video live stream
- k3s change requested UDP port assignment
- Why does the python client socket receiving a reply but still throw the exception in some threadings?
- Gnuradio "double free or corruption (!prev)" error
- Why we need wraparound in UPD checksum algorithm?
- Simple Java UDP server/client-program works on local machine but not over either LAN (different machines) or internet
- Docker bridge does not transmit from tcpreplay IPv6/UDP/GTP traffic
- trying to send TCP packet and recieve it back and count time in client+server app
- recvmsg returns EAGAIN after select reports file descriptor is ready
- Receiving UDP broadcast on Android
Related Questions in ONLINE-GAME
- Creating a new 3rd party program for a game
- Mirror Error: "TargetRPC {functionFullName} can't be sent because it was given a null connection. Make sure {name} is owned by a connection
- Does cloud servers access everywhere in the world
- Socket an invalid argument was supplied in python
- How to avoid Realtime database onWrite trigger function callback iterate data but data has changed
- Java Robot for online game
- Fastpaced online game (2D platformer) - Networking Server/Client
- Receiving data from server in while loop Shows window not responding
- Laser does not shoot after I added a player
- Why do I get the Error: "Cannot read property 'style' of null" on line 216 because of something also on lines 190, 200, 213?
- Zooming image on coordination with javascript
- HTML quiz game with Canvas
- Use redis for object oriented proggramming
- How to make a "Find Match" like Mobile Legends or some other MOBA game?
- Managing multiple games with Node.js and Socket.io
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Your question is, by far, too broad for this platform.
I will answer what I can, briefly.
AJAX /
XMLHttpRequestThe
XMLHttpRequestAPI will (often) open a new connection to the host each time data is sent. This is a very expensive operation and will hurt performance.Another point to consider is that an
XMLHttpRequestwill always send authentication and other headers, wasting both bandwidth and CPU cycles on both client and server.There is also the issue that this approach is often based on polling, so data is sent and processed even if there's no change or update. This is not only a waste, but it might hurt other clients that are waiting for updates.
Finally, AJAX /
XMLHttpRequestwill use a TCP/IP connection, which is great if you must make sure that the whole of the data arrived in order but incurs a performance hit.WebSockets
WebSockets is a protocol that runs over a streaming connection, such as TCP/IP connections (or pipes or unix sockets).
Once the connection is established, it's persistent and it allows two-ways communication. This allows both client and server to initiate an update without polling and without the extra cost (headers, re-authentication, etc').
WebSockets still sits over a streaming socket, such as a TCP/IP socket, which incurs a performance const in exchange for data integrity (all the data arrives in order).
TCP/IP sockets
TCP/IP is a streaming protocol rather than a message based protocol. For this reason it's often used with another protocol (such as WebSockets or a custom authored protocol).
Since WebSockets will use TCP/IP 99.9% of the time (unless on the same machine or on custom-made-special occasions), the same issues I described for WebSockets apply here.
However, by using a custom protocol with TCP/IP, some performance optimizations can be achieved (at a price related to network connectivity and intermediary interference).
UDP (Datagram)
Many games don't require data integrity. It doesn't matter if some packets are lost, it is more important that the latest information arrives as fast as possible.
This is where UDP sockets come in. There's no high-cost connection negotiation stage (as far as round-trips go, UDP is practically free) and there's no data integrity testing layer that might hold-up data that arrived out of order.
For these reasons, some games require UDP sockets for fast updates, while still using a TCP/IP connection for data that must arrive safely.