|
FAQ
Q: How can I tell, on the server, when a client connects?A: Hook the StatusChanged event on the server like this: myServer.StatusChanged += new EventHandler<NetStatusEventArgs>(OnStatusChanged);
...
void OnStatusChanged(object sender, NetStatusEventArgs e)
{
if (e.Connection.Status == NetConnectionStatus.Connected)
Log.Info(e.Connection + " connected!");
}Q: What is bandwidth throttling?A: Throttling enables you to limit the number of bytes sent per second. Trying to send too much data in a very short timespan may create loss and this can be prevented by throttling. To set the default throttling amount for every new connection that is created, use the static field NetConnectionConfiguration.DefaultThrottleBytesPerSecond and to change the throttling of a specific connection, change the Connection.ThrottleBytesPerSecond field. Q: What is the Xna Extension?A: It includes methods for easily writing Xna primitives (vectors, matrices) to a NetMessage, including some compression methods to reduce bandwidth usage. Q: Is Lidgren.Library.Network thread safe?A: No, not really. See best practices for threading and class libraries at the bottom of this document: http://msdn2.microsoft.com/en-us/library/1c9txz50(vs.80).aspx Q: How can I implement a IP ban list?A: Use the ConnectionRequest event like this: static List<IPAddress> m_banList;
...
// insert just after server creation
Server.ConnectionRequest += new EventHandler<NetConnectRequestEventArgs>(Server_ConnectionRequest);
...
static void Server_ConnectionRequest(object sender, NetConnectRequestEventArgs e)
{
// check ip against ban list
if (m_banList.Contains(e.EndPoint.Address))
{
e.MayConnect = false;
e.DenialReason = "Your IP is banned!";
}
}Q: What NetChannel should I use?A: Assuming you've read the description of the different types but still can't decide; here's what you need to ask yourself: Does the data definately absolutely have to arrive?YesMUST all messages arrive in the exact order they were sent?NoYes - Use NetChannel.ReliableUnordered No - Use NetChannel.OrderedWhat happens if a message is delayed, and arrives AFTER a newer message has already arrived?The old data should be discarded - Use NetChannel.Sequenced The old data should be delivered - Use NetChannel.Unreliable Here are some examples: Typical Unreliable message: Player waves hello Typical Sequenced message: Player health and ammo count Typical ReliableUnordered message: Player fires a missile Typical Ordered message: Player sends a chat message Q: What's the difference between Sequenced4 and Sequenced5?A: ... or Ordered2 and Ordered3? It's different channels. Let's take an example: In your game you have a Health meter and an Ammo meter. You've determined that "Sequenced" delivery method is the best (ie. "old" messages are dropped). Now let's say you send a Health message, but it's delayed by bad network conditions. If a later Ammo message arrived before our health message... the health message will be dropped; since it's considered "old". This is not our intention... old Health data is still relevant even if we've received newer Ammo data. So we send them in different channels. Health messages in Sequenced3 and Ammo in Sequenced4 - that way they won't interfere with eachother. The same logic applied to Ordered. Messages in one channel won't be withheld because of dropped messages in another channel. |
Sign in to add a comment
how to connect server use NAT ?
How to receive messages in a xna game without blocking.
How to tell which client has connected & send a reply message on connection?
How do I shot web?