SocketAsyncEventArgs? - simple example - c#

As the progress of my XNA TopDown Shooter game continues, it's time to implement multiplayer functionality.
Because the client and server will have to handle alot of data per second (60 packets per second with position, rotation and other player data) I have to make a stable and fast network system.
My question:
What is the best option to create a very fast, high performance network connection between 1 server and multiple clients?
If the answer is SocketAsyncEventArgs, do you know a simple, clean example somewhere on the internet of how to send and receive data using this advanced class? I can't seem to find a nice example that I understand.
Thanks for your time!
Bas

here's a blog about it
http://socketeering.blogspot.com/
couple youtube videos in the links

Related

Check the data has updated at server without requesting every frame of the game

I have a game where I have to get data from the server (through REST WebService with JSON) but the problem is I don't know when the data will be available on the server. So, I decided to use such a method that hit Server after specific time or on request on every frame of the game. But certainly this is not the right, scale able and efficient approach. Obviously, hammering is not the right choice.
Now my question is that how do I know that data has arrived at server so that I can use this data to run my game. Or how should I direct the back-end team to design the server in an efficient way that it responds efficiently.
Remember at server side I have Python while client side is C# with unity game-engine.
It is clearly difficult to provide an answer with little details. TL;DR is that it depends on what game you are developing. However, polling is very inefficient for at least three reasons:
The former, as you have already pointed out, it is inefficient because you generate additional workload when there is no need
The latter, because it requires TCP - server-generated updates can be sent using UDP instead, with some pros and cons (like potential loss of packets due to lack of ACK)
You may get the updates too late, particularly in the case of multiplayer games. Imagine that the last update happened right after the previous poll, and your poll is each 5 seconds. The status could be already stale.
The long and the short of it is that if you are developing a turn-based game, poll could be alright. If you are developing (as the use of Unity3D would suggest) a real-time game, then server-generated updates, ideally using UDP, are in my opinion the way to go.
Hope that helps and good luck with your project.

Pooling vs sockets vs something else

I have a Windows Phone game that requires support for multiplayer. The multiplayer is similar to the one in Wordament: everyone plays the same game; the client gets the game initially, then the each player plays the game on his own without any interaction with the others and when the game ends, the results from everyone are collected and displayed. The difference is: in my application, the game doesn't end after a specified period of time but rather when one of the clients signals it. So, when someone completes the game (reaches a goal), all the others have to be notified that someone won.
My initial thought is pool the server every let's say 5 seconds to see if the game state has been changed. When a client completes the game, it sends a request with that info and all the other clients, upon the next pool request, will get the new status. This, IMO, is the simplest and most convenient solution because all I need is one byte of data to tell me if the game is over or not.
Real time (as in millisecond accuracy) is not critical. As you might have noticed in the previous paragraph, a 5 seconds delay is acceptable.
However, I am asking you, experts, if a duplex channel would be more appropriate for this scenario? I found solutions like Pusher which provide the two way channel but it seems to me that such a solution is very complex and expensive (we have a very limited budget).
Will share my current knowledge.
Pull(Poll)
Simple to implement, widely used.
Examples: Facebook.com, TeamCity web interface, .NET Client for QPID Message Broker
Push
Take a look at this article
Performance of HTTP polling duplex server-side channel in Microsoft Silverlight 3
What I've noticed for myself: need extra efforts for configuration, possible issues with scalability and performance
The only scenario I can think of - exchange of large amount of data on constant basis
Example: Massively multiplayer online games(huges number of events, notification time is extremely critial)
Get changes on demand
Typical for bussines desktop application.
Examples: TFS(refresh grids(tasks and bugs), get locked file status on check out)
Conclusion: Pooling for your task fits ideally

Server-Client Syncing

I've been looking up on google for this answer, and I just can't find the answer to my question. I have a 2D rpg that I want to build a client-server architecture with. How do I 'sync' things? cause with lag, things are all 'back in time' by the time data reaches the other end. Even with client side interpolation etc, how do I get a 'common time' between clients and the server? Ie, if it took 60ms to go from client->server, -how- does the server know it was 60ms, or 90, 120, etc? The only way would be to have a common time between them somehow, for I could use lag calculations to better sync things? I'm totally lost on his :(
Thanks for any help
Take a look at this question. Since it's not a first person shooter you won't need to send as much information so it should be easier to add in techniques such as prediction and interpolation.
Take a look at the Steam wiki article mentioned in the answer, it's a good starting point.

Multiplayer Game Synchronization

I've a server/client architecture implemented, where all state changes are sent to the function, validated and broadcasted to all clients connected. This works rather well, but the system does not maintain synchronization between the client instances of the game as of now.
If there happened to be a 5 second lag between the server and a particular client then he would receive the state change 5 seconds after the rest of the clients thus leaving him with game state out of sync. I've been searching for various ways to implement a synchronization system between the clients but haven't found much so far.
I'm new to network programming, and not so naive to think that I can invent a working system myself without dedicating a severe amount of time to it. The ideas I've been having, however, is to keep some kind of time system, so each state change would be connected to a specific timestamp in the game. That way when a client received a state change, it would know exactly in which period of the game the changed happened, and would in turn be able to correlate for the lag. The problem with this method is that in those n seconds lag the game would have had continued on the client side, and thus the client would have to rollback in time to update for the state change which definitely would get messy.
So I'm looking for papers discussion the subjects or algorithms that solves it. Perhaps my whole design of how the multiplayer system works is flawed, in the sense that a client's game instance shouldn't update unless notion is received from the server? Right now the clients just update themselves in their game loop assuming that any states haven't changed.
The basic approach to this is something called Dead Reckoning and a quite nice article about it can be found here. Basically it is a predication algorithm for where entities positions will be guessed at for the times between server updates.
There are more advanced methodologies that build on this concept, but it is a good starting point.
Also a description of how this is handled in the source engine (Valve's engine for the first Half Life game) can be found here, the principle is basically the same - until the server tells you otherwise use a prediction algorithm to move the entity along an expected path - but this article handles the effect this has on trying to shoot something in more depth.
The best resources I've found in this area are these two articles from Valve Software:
Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization
Source Multiplayer Networking
There will never be a way to guarantee perfect synchronisation across multiple viewpoints in real time - the laws of physics make it impossible. If the sun exploded now, how could you guarantee that observers on Alpha Centauri see the supernova at the same time as we would on Earth? Information takes time to travel.
Therefore, your choices are to either model everything accurately with latency that may differ from viewer to viewer (which is what you have currently), or model them inaccurately without latency and broadly synchronised across viewers (which is where prediction/dead reckoning/extrapolation come in). Slower games like real time strategy tends to go the first route, faster games go the second route.
In particular, you should never assume that the time it takes to travel will be constant. This means that merely sending start and stop messages to move entities will never suffice under either model. You need to send periodic updates of the actual state (typically several times a second for faster games) so that the recipient can correct error in its predictions and interpolations.
If client see events happening at the rate the server is feeding him, which is the normal way to do it (I've worked with protocols of Ultima Online, KalOnline and a little bit of World of Warcraft), then this momentaneous 5 secounds delay would just make him receive this 5 secounds of events all at once and see those events passing really fast or near instantly, as other players would see him "walking" really fast for a short distance if his outputs delay too. After that everything flows normally again. Actually, except for graphic and physics normalization, I can't see any special needs to make it synchronize properly, it just synchronize itself.
If you ever played Valve games in two near computers you would notice they don't care much about minor details like "the exact place where you died" or "where you dead body gibs flyed to". It is all up to client side and totally affected by latency, but this is irrelevant.
After all, lagged players must accept their condition, or close their damn eMule.
Your best option is to send the changes back to the client from the future, thereby arriving at the client at the same point in time it does for other clients that does not have lag problems.

determining your location using ONLY wifi signals?

i will be working on a project that tries to determine your position using the wifi signal strength from a few access points. i was wondering if anyone knew of any similiar projects or any articles on that topic
if anyone cares: its a research project in at my university. the app is written is used as a playing ground to develop new wifi antenna that are better suited for this type of usage. i only work on the coding part of the project though. oh and its written using c# which is not optional
clarification:
its ONLY wifi. no GPS goodnes for us becaus its supposed to work indoors
the software is supposed to determine your location by using the known locations of the access points and their signal strenghts to tell you where you are. its currently at around 4-5 meters of accuracy
aside from that i already have a working prototype and was just wondering if anything similiar has been done before or if anyone has any tips or ideas for/about the project
Discarding the first 2 answers, where they need to use GPS and A-GPS in the first and a known WiFi network in the second, my answer is:
it sounds easy, but you need to do some homework first, a Survey.
you will need to measure up and create a oval shape (in a paper) with points and percentages of all wifi routers in the camp.
when, lets imagine that you compile 2 routers information, you are ready to go.
get the current wifi points and signal strengths from the user laptop/device and query the database using those values.
give the user their current location.
Example:
in the campus bar you measured that to be in that place you need to have around 55% strength of the signal provided from WiFi Router 1 and 25% of the WiFi Router 2.
To use all this in C#, you should start in this Code Project article to get the signal strengths. Then is just use those returned values with your data that you measured before when doing the first survey.
Hope it helps :) At least, that was what I would do in order to approach this problem.
We did this on a project already determining distance from Access Points, but without the signal triangulation (already covered on other answers here).
I do have a recommendation from the "man, I wish I didn't have to go back and do this" department - it would be to spend extra time on 2 areas:
An easy and repeatable method of calibration using Multiple Data Points. For example, the dropoff from being "very close" to "kinda close" will be a lot more than "really far away" to "really really far" away. It's not going to be a linear slope.
Data Smoothing. As you move, the signal strength will vary unproportionally to your movement (due to obstacles in the path). It will make your results much more accurate if you take a rolling average of the last 5-10 samples of the signal strength rather than just taking the last sample.
You might like to look at the Google Gears Geolocation API. I don't know how easy it is to use from C#, but it may be useful/relevant.
(Disclaimer: I work for Google, but haven't had anything to do with the Geolocation API.)
I wouldn't have thought that signal strength would work well: too many things interfere with it (like walls). But you might try measuring ping times, especially if you threw a hundred pings at the AP and took the average. Most of the time will be the AP digesting the ping and generating the pong, but there will also be a time-of-flight component for the signals. If the AP response time is consistent then you should be able to subtract it and hence compute the distance to the AP. By well-known hyperbolic maths you can then find your position from 3 or 4 APs.
Paul.
Skyhook springs to mind. It depends on people registering the llocation of their APs though.
Goto Wifi in positioning System(WPS), where we use multiple Wifi AP to track a location..
this is implemented by many systems like Google, horizon etc by providing extra security 4 privacy..
I too without knowing this tried on immplimenting this sort of technique..
All d best, we can simplify its complexity by various methods there-by achieving INNOVATIVE to existing infrastructure.
I recommend u to go to the wifi router add-in management & usage before pursing this.
you can try FIND3 project, here's a documentation https://www.internalpositioning.com/doc/, it's API can be used for that purpose and use learning algorithm to constantly learn your position with accuracy. They also have mobile apps (for android only). I'm looking to do something of the same nature.

Categories

Resources