├── Samples
├── Old XNA sample.zip
├── LibraryTestSamples
│ ├── DurableSample
│ │ ├── DurableSample.suo
│ │ ├── DurableClient
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ │ └── DurableServer
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ ├── GarbageThrowerSample
│ │ ├── Client
│ │ │ ├── App.config
│ │ │ ├── Program.cs
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Client.csproj
│ │ ├── Server
│ │ │ ├── App.config
│ │ │ ├── Properties
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Program.cs
│ │ └── GarbageThrowerSample.sln
│ ├── ManySample
│ │ ├── ManyServer
│ │ │ ├── Form1.cs
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.Designer.cs
│ │ └── ManyClients
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ ├── Form1.cs
│ │ │ ├── Program.cs
│ │ │ ├── Client.Designer.cs
│ │ │ ├── Client.cs
│ │ │ └── Form1.Designer.cs
│ ├── SpeedSample
│ │ ├── SpeedClient
│ │ │ ├── Properties
│ │ │ │ ├── Settings.settings
│ │ │ │ ├── Settings.Designer.cs
│ │ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ │ └── SpeedServer
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ └── Form1.cs
│ ├── UnconnectedSample
│ │ └── UnconnectedSample
│ │ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ │ ├── Form1.cs
│ │ │ └── Program.cs
│ └── EncryptionSample
│ │ ├── EncryptionServer
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── EncryptionServer.csproj
│ │ ├── EncryptionClient
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── Program.cs
│ │ └── EncryptionClient.csproj
│ │ └── EncryptionSample.sln
├── MasterServerSample
│ ├── MSCommon
│ │ ├── MasterServerMessageType.cs
│ │ ├── CommonConstants.cs
│ │ ├── Documentation.txt
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── NativeMethods.cs
│ ├── MSClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
│ ├── MSServer
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ └── Program.cs
│ ├── MasterServer
│ │ └── Properties
│ │ │ └── AssemblyInfo.cs
│ └── MasterServerSample.sln
├── Chat
│ ├── ChatClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ ├── AssemblyInfo.cs
│ │ │ └── Resources.Designer.cs
│ │ └── Form1.cs
│ └── ChatServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ └── Resources.Designer.cs
│ │ └── Form1.cs
├── ImageSample
│ ├── ImageClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ ├── AssemblyInfo.cs
│ │ │ └── Resources.Designer.cs
│ │ ├── Form1.cs
│ │ ├── Program.cs
│ │ └── ImageGetter.Designer.cs
│ └── ImageServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ └── Resources.Designer.cs
│ │ └── Form1.cs
├── File stream sample
│ ├── FileStreamClient
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ └── AssemblyInfo.cs
│ │ └── Form1.cs
│ └── FileStreamServer
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ └── AssemblyInfo.cs
│ │ ├── Form1.cs
│ │ ├── StreamingClient.cs
│ │ ├── Program.cs
│ │ └── Form1.Designer.cs
└── SamplesCommon
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── NativeMethods.cs
├── Documentation
├── Documentation.chm
├── ReadMe.txt
└── sandcastle-build-project.shfbproj
├── UnitTests
├── app.config
├── MiscTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── BitVectorTests.cs
├── NetQueueTests.cs
├── Program.cs
└── UnitTests.csproj
├── UnitTests.MultiTarget
├── App.config
└── Properties
│ └── AssemblyInfo.cs
├── .travis.yml
├── Lidgren.Network
├── Documentation
│ ├── ChangedFromV2.txt
│ ├── TODO.txt
│ ├── PacketLayout.txt
│ └── Improvements.txt
├── NetFragmentationInfo.cs
├── NamespaceDoc.cs
├── NetTuple.cs
├── NetStoredReliableMessage.cs
├── NetReceiverChannelBase.cs
├── Encryption
│ ├── NetDESEncryption.cs
│ ├── NetRC2Encryption.cs
│ ├── NetTripleDESEncryption.cs
│ ├── NetAESEncryption.cs
│ ├── NetEncryption.cs
│ ├── NetCryptoProviderEncryption.cs
│ ├── NetXorEncryption.cs
│ └── NetCryptoProviderBase.cs
├── NetUnreliableUnorderedReceiver.cs
├── NetSendResult.cs
├── NetSenderChannelBase.cs
├── NetUnreliableSequencedReceiver.cs
├── NetDeliveryMethod.cs
├── NetRandomSeed.cs
├── Properties
│ └── AssemblyInfo.cs
├── NetTime.cs
├── NetReliableSequencedReceiver.cs
├── NetPeerStatus.cs
├── NetPeer.Discovery.cs
├── NetException.cs
├── Platform
│ ├── PlatformConstrained.cs
│ └── PlatformAndroid.cs
├── NetConnectionStatus.cs
├── NetConstants.cs
├── NetPeer.Logging.cs
├── NetReliableOrderedReceiver.cs
└── NetBuffer.cs
├── UnitTests.Core
└── UnitTests.Core.csproj
├── README.md
├── LICENSE
└── Lidgren.Network.sln
/Samples/Old XNA sample.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lidgren/lidgren-network-gen3/HEAD/Samples/Old XNA sample.zip
--------------------------------------------------------------------------------
/Documentation/Documentation.chm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lidgren/lidgren-network-gen3/HEAD/Documentation/Documentation.chm
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableSample.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lidgren/lidgren-network-gen3/HEAD/Samples/LibraryTestSamples/DurableSample/DurableSample.suo
--------------------------------------------------------------------------------
/UnitTests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/UnitTests.MultiTarget/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | solution: Lidgren.Network.sln
3 | install:
4 | - nuget restore Lidgren.Network.sln
5 | script:
6 | - xbuild /p:Configuration=Release Lidgren.Network.sln
7 | - mono ./UnitTests/bin/Release/UnitTests.exe
8 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSCommon/MasterServerMessageType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MSCommon
4 | {
5 | public enum MasterServerMessageType
6 | {
7 | RegisterHost,
8 | RequestHostList,
9 | RequestIntroduction,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Client/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Server/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace ManyServer
4 | {
5 | public partial class Form1 : Form
6 | {
7 | public Form1()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/ChangedFromV2.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | * The NetBuffer object is gone; instead there are NetOutgoingMessage and NetIncomingMessage objects
4 |
5 | * No need to allocate a read buffer before calling ReadMessage
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Documentation/ReadMe.txt:
--------------------------------------------------------------------------------
1 | In order to read the documentation you may have to unblock it by doing this:
2 |
3 | 1. Right-click the .CHM file and choose Properties
4 | 2. On the General tab, click the button labeled "Unblock"
5 | 3. Click OK
6 |
7 | For reference, see: http://support.microsoft.com/kb/2021383
8 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetFragmentationInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | public sealed class NetFragmentationInfo
6 | {
7 | public int TotalFragmentCount;
8 | public bool[] Received;
9 | public int TotalReceived;
10 | public int FragmentSize;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableClient/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableServer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Lidgren.Network/NamespaceDoc.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// Lidgren Network Library
9 | ///
10 | internal class NamespaceDoc
11 | {
12 | //
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSCommon/CommonConstants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace MSCommon
7 | {
8 | public static class CommonConstants
9 | {
10 | public const int MasterServerPort = 14343;
11 | public const int GameServerPort = 14242;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetTuple.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Lidgren.Network
6 | {
7 | // replace with BCL 4.0 Tuple<> when appropriate
8 | internal struct NetTuple
9 | {
10 | public A Item1;
11 | public B Item2;
12 |
13 | public NetTuple(A item1, B item2)
14 | {
15 | Item1 = item1;
16 | Item2 = item2;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetStoredReliableMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal struct NetStoredReliableMessage
6 | {
7 | public int NumSent;
8 | public double LastSent;
9 | public NetOutgoingMessage Message;
10 | public int SequenceNumber;
11 |
12 | public void Reset()
13 | {
14 | NumSent = 0;
15 | LastSent = 0.0;
16 | Message = null;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetReceiverChannelBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal abstract class NetReceiverChannelBase
6 | {
7 | internal NetPeer m_peer;
8 | internal NetConnection m_connection;
9 |
10 | public NetReceiverChannelBase(NetConnection connection)
11 | {
12 | m_connection = connection;
13 | m_peer = connection.m_peer;
14 | }
15 |
16 | internal abstract void ReceiveMessage(NetIncomingMessage msg);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace FileStreamClient
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | progressBar1.Minimum = 0;
12 | progressBar1.Maximum = 100;
13 | }
14 |
15 | private void button1_Click(object sender, EventArgs e)
16 | {
17 | Program.Connect(textBox1.Text, Int32.Parse(textBox2.Text));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/TODO.txt:
--------------------------------------------------------------------------------
1 |
2 | Completed features:
3 | * Message coalescing
4 | * Peer, connection statistics
5 | * Lag, loss and duplication simulation for testing
6 | * Connection approval
7 | * Throttling
8 | * Clock synchronization to detect jitter per packet (NetTime.RemoteNow)
9 | * Peer discovery
10 | * Message fragmentation
11 |
12 | Missing features:
13 | * Receipts 25% done, need design
14 | * More realistic lag/loss (lumpy)
15 | * Detect estimated packet loss
16 | * More advanced ack packet
17 |
18 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/PacketLayout.txt:
--------------------------------------------------------------------------------
1 |
2 | PER MESSAGE:
3 | 7 bits - NetMessageType
4 | 1 bit - Is a message fragment?
5 |
6 | [8 bits NetMessageLibraryType, if NetMessageType == Library]
7 |
8 | [16 bits sequence number, if NetMessageType >= UserSequenced]
9 |
10 | 8/16 bits - Payload length in bits (variable size ushort)
11 |
12 | [16 bits fragments group id, if fragmented]
13 | [16 bits fragments total count, if fragmented]
14 | [16 bits fragment number, if fragmented]
15 |
16 | [x - Payload] if length > 0
17 |
18 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 | namespace ManyClients
11 | {
12 | public partial class Form1 : Form
13 | {
14 | public Form1()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void button1_Click(object sender, EventArgs e)
20 | {
21 | Program.CreateClient();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace FileStreamServer
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | private void button1_Click(object sender, EventArgs e)
14 | {
15 | OpenFileDialog dlg = new OpenFileDialog();
16 | dlg.CheckFileExists = true;
17 | var res = dlg.ShowDialog();
18 |
19 | if (res != DialogResult.OK)
20 | return;
21 |
22 | Program.Start(dlg.FileName);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace UnconnectedSample
5 | {
6 | public partial class Form1 : Form
7 | {
8 | public Form1()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | private void button1_Click(object sender, EventArgs e)
14 | {
15 | uint port;
16 | if (UInt32.TryParse(textBox2.Text, out port) == false)
17 | {
18 | MessageBox.Show("Please fill in the port of the target peer");
19 | return;
20 | }
21 |
22 | Program.Send(textBox1.Text, (int)port, textBox3.Text);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetDESEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public class NetDESEncryption : NetCryptoProviderBase
8 | {
9 | public NetDESEncryption(NetPeer peer)
10 | : base(peer, new DESCryptoServiceProvider())
11 | {
12 | }
13 |
14 | public NetDESEncryption(NetPeer peer, string key)
15 | : base(peer, new DESCryptoServiceProvider())
16 | {
17 | SetKey(key);
18 | }
19 |
20 | public NetDESEncryption(NetPeer peer, byte[] data, int offset, int count)
21 | : base(peer, new DESCryptoServiceProvider())
22 | {
23 | SetKey(data, offset, count);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetRC2Encryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public class NetRC2Encryption : NetCryptoProviderBase
8 | {
9 | public NetRC2Encryption(NetPeer peer)
10 | : base(peer, new RC2CryptoServiceProvider())
11 | {
12 | }
13 |
14 | public NetRC2Encryption(NetPeer peer, string key)
15 | : base(peer, new RC2CryptoServiceProvider())
16 | {
17 | SetKey(key);
18 | }
19 |
20 | public NetRC2Encryption(NetPeer peer, byte[] data, int offset, int count)
21 | : base(peer, new RC2CryptoServiceProvider())
22 | {
23 | SetKey(data, offset, count);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetUnreliableUnorderedReceiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal sealed class NetUnreliableUnorderedReceiver : NetReceiverChannelBase
6 | {
7 | private bool m_doFlowControl;
8 |
9 | public NetUnreliableUnorderedReceiver(NetConnection connection)
10 | : base(connection)
11 | {
12 | m_doFlowControl = connection.Peer.Configuration.SuppressUnreliableUnorderedAcks == false;
13 | }
14 |
15 | internal override void ReceiveMessage(NetIncomingMessage msg)
16 | {
17 | if (m_doFlowControl)
18 | m_connection.QueueAck(msg.m_receivedMessageType, msg.m_sequenceNumber);
19 |
20 | m_peer.ReleaseMessage(msg);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetSendResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | ///
6 | /// Result of a SendMessage call
7 | ///
8 | public enum NetSendResult
9 | {
10 | ///
11 | /// Message failed to enqueue because there is no connection
12 | ///
13 | FailedNotConnected = 0,
14 |
15 | ///
16 | /// Message was immediately sent
17 | ///
18 | Sent = 1,
19 |
20 | ///
21 | /// Message was queued for delivery
22 | ///
23 | Queued = 2,
24 |
25 | ///
26 | /// Message was dropped immediately since too many message were queued
27 | ///
28 | Dropped = 3
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetTripleDESEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public class NetTripleDESEncryption : NetCryptoProviderBase
8 | {
9 | public NetTripleDESEncryption(NetPeer peer)
10 | : base(peer, new TripleDESCryptoServiceProvider())
11 | {
12 | }
13 |
14 | public NetTripleDESEncryption(NetPeer peer, string key)
15 | : base(peer, new TripleDESCryptoServiceProvider())
16 | {
17 | SetKey(key);
18 | }
19 |
20 | public NetTripleDESEncryption(NetPeer peer, byte[] data, int offset, int count)
21 | : base(peer, new TripleDESCryptoServiceProvider())
22 | {
23 | SetKey(data, offset, count);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using SamplesCommon;
5 |
6 | namespace DurableServer
7 | {
8 | public partial class Form1 : Form
9 | {
10 | private NetPeerSettingsWindow m_settingsWindow;
11 |
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | if (m_settingsWindow == null)
20 | {
21 | m_settingsWindow = new NetPeerSettingsWindow("Durable server settings", Program.Server);
22 | m_settingsWindow.Show();
23 | }
24 | else
25 | {
26 | m_settingsWindow.Close();
27 | m_settingsWindow = null;
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Text;
5 | using System.Windows.Forms;
6 |
7 | namespace ChatServer
8 | {
9 | public partial class Form1 : Form
10 | {
11 | public Form1()
12 | {
13 | InitializeComponent();
14 | }
15 |
16 | private void button1_Click(object sender, EventArgs e)
17 | {
18 | if (button1.Text == "Start")
19 | {
20 | Program.StartServer();
21 | button1.Text = "Shut down";
22 | }
23 | else
24 | {
25 | Program.Shutdown();
26 | button1.Text = "Start";
27 | }
28 | }
29 |
30 | private void button2_Click(object sender, EventArgs e)
31 | {
32 | Program.DisplaySettings();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace SpeedTestServer
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | Program.DisplaySettings();
20 | }
21 |
22 | private void button2_Click(object sender, EventArgs e)
23 | {
24 | if (button2.Text == "Start")
25 | {
26 | Program.Start();
27 | button2.Text = "Shutdown";
28 | }
29 | else
30 | {
31 | Program.Shutdown();
32 | button2.Text = "Start";
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 | namespace MSClient
11 | {
12 | public partial class Form1 : Form
13 | {
14 | public Form1()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void button1_Click(object sender, EventArgs e)
20 | {
21 | Program.GetServerList(textBox1.Text);
22 | }
23 |
24 | private void button2_Click(object sender, EventArgs e)
25 | {
26 | if (comboBox1.SelectedItem == null)
27 | return;
28 |
29 | var splits = comboBox1.SelectedItem.ToString().Split(' ');
30 | var host = Int64.Parse(splits[0]);
31 | Program.RequestNATIntroduction(host);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace SpeedTestClient
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | comboBox1.SelectedIndex = 0;
16 | }
17 |
18 | private void button2_Click(object sender, EventArgs e)
19 | {
20 | int seqChan;
21 | Int32.TryParse(textBox3.Text, out seqChan);
22 | int port;
23 | Int32.TryParse(textBox2.Text, out port);
24 | Program.Connect(textBox1.Text, port, comboBox1.SelectedItem.ToString(), seqChan);
25 | }
26 |
27 | private void button1_Click(object sender, EventArgs e)
28 | {
29 | Program.DisplaySettings();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/UnitTests.Core/UnitTests.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetSenderChannelBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal abstract class NetSenderChannelBase
6 | {
7 | // access this directly to queue things in this channel
8 | protected NetQueue m_queuedSends;
9 |
10 | internal abstract int WindowSize { get; }
11 |
12 | internal abstract int GetAllowedSends();
13 |
14 | internal int QueuedSendsCount { get { return m_queuedSends.Count; } }
15 |
16 | internal virtual bool NeedToSendMessages() { return m_queuedSends.Count > 0; }
17 |
18 | public int GetFreeWindowSlots()
19 | {
20 | return GetAllowedSends() - m_queuedSends.Count;
21 | }
22 |
23 | internal abstract NetSendResult Enqueue(NetOutgoingMessage message);
24 | internal abstract void SendQueuedMessages(double now);
25 | internal abstract void Reset();
26 | internal abstract void ReceiveAcknowledge(double now, int sequenceNumber);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetAESEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public class NetAESEncryption : NetCryptoProviderBase
8 | {
9 | public NetAESEncryption(NetPeer peer)
10 | #if UNITY
11 | : base(peer, new RijndaelManaged())
12 | #else
13 | : base(peer, new AesCryptoServiceProvider())
14 | #endif
15 | {
16 | }
17 |
18 | public NetAESEncryption(NetPeer peer, string key)
19 | #if UNITY
20 | : base(peer, new RijndaelManaged())
21 | #else
22 | : base(peer, new AesCryptoServiceProvider())
23 | #endif
24 | {
25 | SetKey(key);
26 | }
27 |
28 | public NetAESEncryption(NetPeer peer, byte[] data, int offset, int count)
29 | #if UNITY
30 | : base(peer, new RijndaelManaged())
31 | #else
32 | : base(peer, new AesCryptoServiceProvider())
33 | #endif
34 | {
35 | SetKey(data, offset, count);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using SamplesCommon;
5 |
6 | namespace DurableClient
7 | {
8 | public partial class Form1 : Form
9 | {
10 | private NetPeerSettingsWindow m_settingsWindow;
11 |
12 | public Form1()
13 | {
14 | InitializeComponent();
15 | }
16 |
17 | private void button1_Click(object sender, EventArgs e)
18 | {
19 | if (string.IsNullOrEmpty(textBox1.Text))
20 | textBox1.Text = "localhost";
21 |
22 | Program.Connect(textBox1.Text);
23 | }
24 |
25 | private void button2_Click(object sender, EventArgs e)
26 | {
27 | if (m_settingsWindow == null)
28 | {
29 | m_settingsWindow = new NetPeerSettingsWindow("Durable client settings", Program.Client);
30 | m_settingsWindow.Show();
31 | }
32 | else
33 | {
34 | m_settingsWindow.Close();
35 | m_settingsWindow = null;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using Lidgren.Network;
9 | using SamplesCommon;
10 |
11 | namespace ImageClient
12 | {
13 | public partial class Form1 : Form
14 | {
15 | private NetPeer m_dummyPeer;
16 | private NetPeerConfiguration m_config;
17 |
18 | public Form1()
19 | {
20 | m_config = new NetPeerConfiguration("ImageTransfer");
21 | m_dummyPeer = new NetPeer(m_config);
22 | InitializeComponent();
23 | }
24 |
25 | private void button1_Click(object sender, EventArgs e)
26 | {
27 | Program.SpawnGetter(textBox1.Text, m_config);
28 | }
29 |
30 | private void button2_Click(object sender, EventArgs e)
31 | {
32 | NetPeerSettingsWindow win = new NetPeerSettingsWindow("Client settings", m_dummyPeer);
33 | win.Show();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetUnreliableSequencedReceiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal sealed class NetUnreliableSequencedReceiver : NetReceiverChannelBase
6 | {
7 | private int m_lastReceivedSequenceNumber = -1;
8 |
9 | public NetUnreliableSequencedReceiver(NetConnection connection)
10 | : base(connection)
11 | {
12 | }
13 |
14 | internal override void ReceiveMessage(NetIncomingMessage msg)
15 | {
16 | int nr = msg.m_sequenceNumber;
17 |
18 | // ack no matter what
19 | m_connection.QueueAck(msg.m_receivedMessageType, nr);
20 |
21 | int relate = NetUtility.RelativeSequenceNumber(nr, m_lastReceivedSequenceNumber + 1);
22 | if (relate < 0)
23 | {
24 | m_connection.m_statistics.MessageDropped();
25 | m_peer.LogVerbose("Received message #" + nr + " DROPPING DUPLICATE");
26 | return; // drop if late
27 | }
28 |
29 | m_lastReceivedSequenceNumber = nr;
30 | m_peer.ReleaseMessage(msg);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/UnitTests/MiscTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Lidgren.Network;
4 |
5 | namespace UnitTests
6 | {
7 | public static class MiscTests
8 | {
9 | public static void Run(NetPeer peer)
10 | {
11 | NetPeerConfiguration config = new NetPeerConfiguration("Test");
12 |
13 | config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
14 | if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
15 | throw new NetException("setting enabled message types failed");
16 |
17 | config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
18 | if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
19 | throw new NetException("setting enabled message types failed");
20 |
21 | Console.WriteLine("Misc tests OK");
22 |
23 | Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
24 |
25 | if (NetUtility.BitsToHoldUInt64((ulong)UInt32.MaxValue + 1ul) != 33)
26 | throw new NetException("BitsToHoldUInt64 failed");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **Note! Not actively developed any more; only accepting trivial or minor bug fixes.**
2 |
3 | # Lidgren.Network 
4 | Lidgren.Network is a networking library for .NET framework, which uses a single UDP socket to deliver a simple API for connecting a client to a server, reading and sending messages.
5 |
6 | This has been updated for use with Unity3D, feel free to send PRs for other bugs fixes.
7 | To use this in Unity3D just enable the experimental .NET framework.
8 | you can do this in Edit -> Project Settings -> Player -> Other Settings -> Api Compatibility Level -> .NET 4.6
9 |
10 | Platforms supported:
11 | - Linux
12 | - Mac
13 | - OSX
14 |
15 | Platforms/Toolchains which need testing:
16 | - Android
17 | - iPhone
18 | - Xamarin
19 |
20 | Tested in:
21 | - Mono (alpha and beta)
22 | - .NET 4.6
23 | - Unity 2017.1 -> 2018.1.
24 |
25 | Future Roadmap:
26 | - Update to latest .NET 4.6
27 | - Investigate officially supporting .NET Core.
28 | - Improve test suite so that tests are run on all platforms we support, for each release.
29 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 | using SamplesCommon;
6 |
7 | namespace ManyClients
8 | {
9 | static class Program
10 | {
11 | public static List Clients;
12 |
13 | [STAThread]
14 | static void Main()
15 | {
16 | Application.EnableVisualStyles();
17 | Application.SetCompatibleTextRenderingDefault(false);
18 |
19 | Clients = new List();
20 |
21 | Application.Idle += new EventHandler(AppIdle);
22 | Application.Run(new Form1());
23 |
24 | foreach (var c in Clients)
25 | c.Shutdown();
26 | }
27 |
28 | static void AppIdle(object sender, EventArgs e)
29 | {
30 | while (NativeMethods.AppStillIdle)
31 | {
32 | foreach (var c in Clients)
33 | c.Heartbeat();
34 | System.Threading.Thread.Sleep(1);
35 | }
36 | }
37 |
38 | internal static void CreateClient()
39 | {
40 | Client client = new Client();
41 | client.Show();
42 | Clients.Add(client);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 lidgren
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetDeliveryMethod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// How the library deals with resends and handling of late messages
9 | ///
10 | public enum NetDeliveryMethod : byte
11 | {
12 | //
13 | // Actually a publicly visible subset of NetMessageType
14 | //
15 |
16 | ///
17 | /// Indicates an error
18 | ///
19 | Unknown = 0,
20 |
21 | ///
22 | /// Unreliable, unordered delivery
23 | ///
24 | Unreliable = 1,
25 |
26 | ///
27 | /// Unreliable delivery, but automatically dropping late messages
28 | ///
29 | UnreliableSequenced = 2,
30 |
31 | ///
32 | /// Reliable delivery, but unordered
33 | ///
34 | ReliableUnordered = 34,
35 |
36 | ///
37 | /// Reliable delivery, except for late messages which are dropped
38 | ///
39 | ReliableSequenced = 35,
40 |
41 | ///
42 | /// Reliable, ordered delivery
43 | ///
44 | ReliableOrdered = 67,
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageServer/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using SamplesCommon;
9 |
10 | namespace ImageServer
11 | {
12 | public partial class Form1 : Form
13 | {
14 | private NetPeerSettingsWindow m_settingsWindow;
15 |
16 | public Form1()
17 | {
18 | InitializeComponent();
19 | }
20 |
21 | private void button1_Click(object sender, EventArgs e)
22 | {
23 | if (m_settingsWindow == null)
24 | {
25 | m_settingsWindow = new NetPeerSettingsWindow("Image server settings", Program.Server);
26 | m_settingsWindow.Show();
27 | }
28 | else
29 | {
30 | m_settingsWindow.Close();
31 | m_settingsWindow = null;
32 | }
33 | }
34 |
35 | private void button2_Click(object sender, EventArgs e)
36 | {
37 | OpenFileDialog dlg = new OpenFileDialog();
38 | dlg.Filter = "Image files|*.png;*.jpg;*.jpeg";
39 | DialogResult res = dlg.ShowDialog();
40 | if (res != DialogResult.OK)
41 | return;
42 | Program.Start(dlg.FileName);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// Interface for an encryption algorithm
9 | ///
10 | public abstract class NetEncryption
11 | {
12 | ///
13 | /// NetPeer
14 | ///
15 | protected NetPeer m_peer;
16 |
17 | ///
18 | /// Constructor
19 | ///
20 | public NetEncryption(NetPeer peer)
21 | {
22 | if (peer == null)
23 | throw new NetException("Peer must not be null");
24 | m_peer = peer;
25 | }
26 |
27 | public void SetKey(string str)
28 | {
29 | var bytes = System.Text.Encoding.ASCII.GetBytes(str);
30 | SetKey(bytes, 0, bytes.Length);
31 | }
32 |
33 | public abstract void SetKey(byte[] data, int offset, int count);
34 |
35 | ///
36 | /// Encrypt an outgoing message in place
37 | ///
38 | public abstract bool Encrypt(NetOutgoingMessage msg);
39 |
40 | ///
41 | /// Decrypt an incoming message in place
42 | ///
43 | public abstract bool Decrypt(NetIncomingMessage msg);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MSClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace FileStreamClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace FileStreamServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ManyClients.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ManyServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SpeedTestClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SpeedTestServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableClient/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DurableClient.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableServer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace DurableServer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UnconnectedSample.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Lidgren.Network/Documentation/Improvements.txt:
--------------------------------------------------------------------------------
1 |
2 | Improvements over last version of library:
3 |
4 | * New delivery type: Reliable sequenced (Lost packets are resent but late arrivals are dropped)
5 | * Disconnects and shutdown requests are now queued properly, so calling shutdown will still send any queued messages before shutting down
6 | * All messages are pooled/recycled for zero garbage
7 | * Reduced CPU usage and lower latencies (in the <1 ms range, but still) due to better socket polling
8 | * All public members of NetPeer/NetConnection are completely thread safe
9 | * Larger number of delivery channels
10 | * More exact roundtrip measurement
11 | * Method serialize entire objects via reflection
12 | * Unique identifier now exists for all peers/connections
13 | * More flexible peer discovery; filters possible and arbitrary data can be sent with response
14 | * Much better protection against malformed messages crashing the app
15 |
16 | API enhancements:
17 | * NetPeerConfiguration immutable properties now locked once NetPeer is initialized
18 | * Messages cannot be send twice by accident
19 | * Impossible to confuse sending and receiving buffers since they're different classes
20 | * No more confusion if user should create a buffer or preallocate and reuse
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetRandomSeed.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace Lidgren.Network
5 | {
6 | ///
7 | /// Class for generating random seeds
8 | ///
9 | public static class NetRandomSeed
10 | {
11 | private static int m_seedIncrement = -1640531527;
12 |
13 | ///
14 | /// Generates a 32 bit random seed
15 | ///
16 | [CLSCompliant(false)]
17 | public static uint GetUInt32()
18 | {
19 | ulong seed = GetUInt64();
20 | uint low = (uint)seed;
21 | uint high = (uint)(seed >> 32);
22 | return low ^ high;
23 | }
24 |
25 | ///
26 | /// Generates a 64 bit random seed
27 | ///
28 | [CLSCompliant(false)]
29 | public static ulong GetUInt64()
30 | {
31 | var guidBytes = Guid.NewGuid().ToByteArray();
32 | ulong seed =
33 | ((ulong)guidBytes[0] << (8 * 0)) |
34 | ((ulong)guidBytes[1] << (8 * 1)) |
35 | ((ulong)guidBytes[2] << (8 * 2)) |
36 | ((ulong)guidBytes[3] << (8 * 3)) |
37 | ((ulong)guidBytes[4] << (8 * 4)) |
38 | ((ulong)guidBytes[5] << (8 * 5)) |
39 | ((ulong)guidBytes[6] << (8 * 6)) |
40 | ((ulong)guidBytes[7] << (8 * 7));
41 |
42 | return seed ^ NetUtility.GetPlatformSeed(m_seedIncrement);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 | using SamplesCommon;
6 | using Lidgren.Network;
7 |
8 | namespace ImageClient
9 | {
10 | static class Program
11 | {
12 | public static Form1 MainForm;
13 | public static List Getters = new List();
14 |
15 | [STAThread]
16 | static void Main()
17 | {
18 | Application.EnableVisualStyles();
19 | Application.SetCompatibleTextRenderingDefault(false);
20 | MainForm = new Form1();
21 |
22 | try
23 | {
24 | Application.Idle += new EventHandler(AppLoop);
25 | Application.Run(MainForm);
26 | }
27 | catch (Exception ex)
28 | {
29 | MessageBox.Show("Ouch: " + ex);
30 | }
31 | }
32 |
33 | static void AppLoop(object sender, EventArgs e)
34 | {
35 | while (NativeMethods.AppStillIdle)
36 | {
37 | foreach (ImageGetter getter in Getters)
38 | getter.Heartbeat();
39 | System.Threading.Thread.Sleep(1);
40 | }
41 | }
42 |
43 | internal static void SpawnGetter(string host, NetPeerConfiguration copyConfig)
44 | {
45 | ImageGetter getter = new ImageGetter(host, copyConfig);
46 | Getters.Add(getter);
47 | getter.Show();
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSCommon/Documentation.txt:
--------------------------------------------------------------------------------
1 |
2 | C is a computer behind a NAT
3 | H is a computer behind a different NAT
4 | M is a computer not behind a NAT
5 |
6 | H wishes to host a game and C wishes to join it, but since they are both behind NAT they cannot contact eachother directly. M must help.
7 |
8 | -------
9 |
10 | 1. H sends a message to M, registering itself as a game host. H is added to the host list at M. (sample code)
11 |
12 | 2. C requests the host list from M. (sample code)
13 |
14 | 3. C reads the host list and decides to join the game hosted by H. (sample code)
15 |
16 | 3. C sends a request to M for introduction between C and H. (sample code)
17 |
18 | 4. M gets the request and sends a NatIntroduction message to both C and H with their external addresses. (NetPeer.Introduce())
19 |
20 | 5a. C gets the intro message and sends a NAT punch message to the external address of H (automatically by library)
21 | 5b. H gets the intro message and sends a NAT punch message to the external address of C (automatically by library)
22 |
23 | 6. If everything goes well, C will get the punch message from H and both NAT routers are now properly configured.
24 |
25 | 7. C will receive a NatIntroductionSuccess message and can now call Connect() as usual (automatically by library)
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Client/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 | using System.Threading;
6 | using System.Net;
7 |
8 | namespace Client
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");
15 | var client = new NetClient(config);
16 |
17 | client.Start();
18 |
19 | var target = new IPEndPoint(NetUtility.Resolve("localhost"), 14242);
20 | var buffer = new byte[1024];
21 | var rnd = new Random();
22 |
23 | int batch = 0;
24 | // use RawSend to throw poop at server
25 | while(true)
26 | {
27 | rnd.NextBytes(buffer);
28 | int length = rnd.Next(1, 1023);
29 |
30 | switch (rnd.Next(2))
31 | {
32 | case 0:
33 | // complete randomness
34 | break;
35 | case 1:
36 | // semi-sensical
37 | buffer[1] = 0; // not a fragment, sequence number 0
38 | buffer[2] = 0; // not a fragment, sequence number 0
39 | buffer[3] = (byte)length; // correct payload length
40 | buffer[4] = (byte)(length >> 8); // correct payload length
41 | break;
42 | }
43 |
44 | // fling teh poop
45 | client.RawSend(buffer, 0, length, target);
46 |
47 | batch++;
48 | if (batch >= 3)
49 | {
50 | batch = 0;
51 | Thread.Sleep(0);
52 | }
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Program.cs:
--------------------------------------------------------------------------------
1 | using Lidgren.Network;
2 | using System;
3 |
4 | namespace EncryptionServer
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | var config = new NetPeerConfiguration("enctest");
11 | config.MaximumConnections = 1;
12 | config.Port = 14242;
13 | var server = new NetServer(config);
14 | server.Start();
15 |
16 | var encryption = new NetAESEncryption(server, "Hallonpalt");
17 |
18 | // loop forever
19 | while (true)
20 | {
21 | var inc = server.ReadMessage();
22 | if (inc != null)
23 | {
24 | switch (inc.MessageType)
25 | {
26 | case NetIncomingMessageType.DebugMessage:
27 | case NetIncomingMessageType.WarningMessage:
28 | case NetIncomingMessageType.VerboseDebugMessage:
29 | case NetIncomingMessageType.ErrorMessage:
30 | Console.WriteLine(inc.ReadString());
31 | break;
32 | case NetIncomingMessageType.StatusChanged:
33 | var status = (NetConnectionStatus)inc.ReadByte();
34 | Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
35 | break;
36 | case NetIncomingMessageType.Data:
37 | var ok = inc.Decrypt(encryption);
38 | Console.WriteLine("Data (decrypted: " + (ok ? "ok" : "fail") + ") " + inc.ReadString());
39 | break;
40 | }
41 | }
42 | System.Threading.Thread.Sleep(1);
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/UnitTests.MultiTarget/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UnitTests.MultiTarget")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UnitTests.MultiTarget")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("692c5016-356c-4fb0-ad7c-4b9801d14bbb")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/UnitTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UnitTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("16f9f241-4a7e-4f96-8be7-8f5c609b5d48")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ChatClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ChatClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("585ecb61-e1fb-4a44-8a0c-2bc06d450fe4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ChatServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ChatServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9ef4cd93-2efb-4c87-8cf3-ef329d157b94")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ImageClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ImageClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b29fc143-5a2c-462d-9df3-04320a9d5e13")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ImageServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ImageServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ce1aecdc-6beb-43b4-828a-fd395fc7e188")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Client")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Client")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0c9a409f-00cd-4b05-87f6-6f4a86d82987")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Server/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Server")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Server")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("afeebf34-cb2c-4377-ace7-5c55f2882c0d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/SamplesCommon/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SamplesCommon")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("SamplesCommon")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7d1622f4-1dc7-4e94-8ec0-0a2a295dcf9a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetCryptoProviderEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public abstract class NetCryptoProviderEncryption : NetEncryption
8 | {
9 | public NetCryptoProviderEncryption(NetPeer peer)
10 | : base(peer)
11 | {
12 | }
13 |
14 | protected abstract CryptoStream GetEncryptStream(MemoryStream ms);
15 |
16 | protected abstract CryptoStream GetDecryptStream(MemoryStream ms);
17 |
18 | public override bool Encrypt(NetOutgoingMessage msg)
19 | {
20 | int unEncLenBits = msg.LengthBits;
21 |
22 | var ms = new MemoryStream();
23 | var cs = GetEncryptStream(ms);
24 | cs.Write(msg.m_data, 0, msg.LengthBytes);
25 | cs.Close();
26 |
27 | // get results
28 | var arr = ms.ToArray();
29 | ms.Close();
30 |
31 | msg.EnsureBufferSize((arr.Length + 4) * 8);
32 | msg.LengthBits = 0; // reset write pointer
33 | msg.Write((uint)unEncLenBits);
34 | msg.Write(arr);
35 | msg.LengthBits = (arr.Length + 4) * 8;
36 |
37 | return true;
38 | }
39 |
40 | public override bool Decrypt(NetIncomingMessage msg)
41 | {
42 | int unEncLenBits = (int)msg.ReadUInt32();
43 |
44 | var ms = new MemoryStream(msg.m_data, 4, msg.LengthBytes - 4);
45 | var cs = GetDecryptStream(ms);
46 |
47 | var result = m_peer.GetStorage(unEncLenBits);
48 | cs.Read(result, 0, NetUtility.BytesToHoldBits(unEncLenBits));
49 | cs.Close();
50 |
51 | // TODO: recycle existing msg
52 |
53 | msg.m_data = result;
54 | msg.m_bitLength = unEncLenBits;
55 |
56 | return true;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ManyServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ManyServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("38556e1a-2608-406f-869b-2935943be269")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SpeedClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SpeedClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dcd70d6e-8d70-460c-a2dd-0ac9d36237ab")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/SpeedSample/SpeedServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SpeedServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SpeedServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2def9135-b4c4-4988-addb-fc00a0fe2f3a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSClient")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("bedb3e73-43c8-4b0d-a982-528a08a745c6")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSCommon/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSCommon")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSCommon")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("24cc031a-d470-439a-89f6-573e5ea1d969")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MSServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MSServer")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c265af7f-3dad-4edf-8ff7-44f03eb2c8e4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FileStreamClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FileStreamClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2937bc24-32d3-461a-85d9-7235380742f0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FileStreamServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FileStreamServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("89332fe6-d655-4932-98c6-77bd03dee333")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DurableClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DurableClient")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("af8ebf93-f447-4c22-8fc3-fb02e2e16b13")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/DurableSample/DurableServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DurableServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DurableServer")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6ad0e88c-40c0-4ca8-bc4c-91a8b64b5776")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MasterServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MasterServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("MasterServer")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("649338d3-b80b-4710-b801-21e593935c21")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Lidgren.Network/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Lidgren.Network")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Lidgren.Network")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("78f2a988-46e1-4fc4-b7b4-dd2cbe46da6a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("2012.1.7.0")]
36 | [assembly: AssemblyFileVersion("2012.1.7.0")]
37 | [assembly: System.CLSCompliant(true)]
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ManyClients")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("ManyClients")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("140e8b00-0bb5-4e9e-847c-56ad106f01a4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UnconnectedSample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("UnconnectedSample")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("615bd8c4-8874-4171-91dc-677905db3e40")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EncryptionClient")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("EA Digital Illusions CE AB")]
12 | [assembly: AssemblyProduct("EncryptionClient")]
13 | [assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6146cc08-8436-4a5b-9cb9-d8a646bdadc0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EncryptionServer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("EA Digital Illusions CE AB")]
12 | [assembly: AssemblyProduct("EncryptionServer")]
13 | [assembly: AssemblyCopyright("Copyright © EA Digital Illusions CE AB 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("20821c63-4381-4c9f-9c34-e8f8d5ca39b5")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatClient/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Windows.Forms;
7 |
8 | namespace ChatClient
9 | {
10 | public partial class Form1 : Form
11 | {
12 | public Form1()
13 | {
14 | InitializeComponent();
15 |
16 | textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);
17 | }
18 |
19 | public void EnableInput()
20 | {
21 | textBox1.Enabled = true;
22 | button1.Enabled = true;
23 | }
24 |
25 | public void DisableInput()
26 | {
27 | textBox1.Enabled = false;
28 | button1.Enabled = false;
29 | }
30 |
31 | void textBox1_KeyDown(object sender, KeyEventArgs e)
32 | {
33 | if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter)
34 | {
35 | // return is equivalent to clicking "send"
36 | button1_Click(sender, e);
37 | }
38 | }
39 |
40 | private void button3_Click(object sender, EventArgs e)
41 | {
42 | Program.DisplaySettings();
43 | }
44 |
45 | private void button2_Click(object sender, EventArgs e)
46 | {
47 | if (button2.Text == "Connect")
48 | {
49 | int port;
50 | Int32.TryParse(textBox3.Text, out port);
51 | Program.Connect(textBox2.Text, port);
52 | button2.Text = "Disconnect";
53 | }
54 | else
55 | {
56 | Program.Shutdown();
57 | button2.Text = "Connect";
58 | }
59 | }
60 |
61 | private void button1_Click(object sender, EventArgs e)
62 | {
63 | // Send
64 | if (!string.IsNullOrEmpty(textBox1.Text))
65 | Program.Send(textBox1.Text);
66 | textBox1.Text = "";
67 |
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetXorEncryption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Lidgren.Network
6 | {
7 | ///
8 | /// Example class; not very good encryption
9 | ///
10 | public class NetXorEncryption : NetEncryption
11 | {
12 | private byte[] m_key;
13 |
14 | ///
15 | /// NetXorEncryption constructor
16 | ///
17 | public NetXorEncryption(NetPeer peer, byte[] key)
18 | : base(peer)
19 | {
20 | m_key = key;
21 | }
22 |
23 | public override void SetKey(byte[] data, int offset, int count)
24 | {
25 | m_key = new byte[count];
26 | Array.Copy(data, offset, m_key, 0, count);
27 | }
28 |
29 | ///
30 | /// NetXorEncryption constructor
31 | ///
32 | public NetXorEncryption(NetPeer peer, string key)
33 | : base(peer)
34 | {
35 | m_key = Encoding.UTF8.GetBytes(key);
36 | }
37 |
38 | ///
39 | /// Encrypt an outgoing message
40 | ///
41 | public override bool Encrypt(NetOutgoingMessage msg)
42 | {
43 | int numBytes = msg.LengthBytes;
44 | for (int i = 0; i < numBytes; i++)
45 | {
46 | int offset = i % m_key.Length;
47 | msg.m_data[i] = (byte)(msg.m_data[i] ^ m_key[offset]);
48 | }
49 | return true;
50 | }
51 |
52 | ///
53 | /// Decrypt an incoming message
54 | ///
55 | public override bool Decrypt(NetIncomingMessage msg)
56 | {
57 | int numBytes = msg.LengthBytes;
58 | for (int i = 0; i < numBytes; i++)
59 | {
60 | int offset = i % m_key.Length;
61 | msg.m_data[i] = (byte)(msg.m_data[i] ^ m_key[offset]);
62 | }
63 | return true;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSCommon/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Windows.Forms;
5 |
6 | namespace MSCommon
7 | {
8 | public static class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
11 | public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
12 | public const int WM_VSCROLL = 277; // Vertical scroll
13 | public const int SB_BOTTOM = 7; // Scroll to bottom
14 |
15 | [StructLayout(LayoutKind.Sequential)]
16 | public struct PeekMsg
17 | {
18 | public IntPtr hWnd;
19 | public Message msg;
20 | public IntPtr wParam;
21 | public IntPtr lParam;
22 | public uint time;
23 | public System.Drawing.Point p;
24 | }
25 |
26 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
27 | [DllImport("User32.dll", CharSet = CharSet.Auto)]
28 | public static extern bool PeekMessage(out PeekMsg msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
29 |
30 | public static bool AppStillIdle
31 | {
32 | get
33 | {
34 | PeekMsg msg;
35 | return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
36 | }
37 | }
38 |
39 | public static void AppendText(RichTextBox box, string line)
40 | {
41 | try
42 | {
43 | box.AppendText(line + Environment.NewLine);
44 | ScrollRichTextBox(box);
45 | }
46 | catch
47 | {
48 | }
49 | }
50 |
51 | public static void ScrollRichTextBox(RichTextBox box)
52 | {
53 | if (box == null || box.IsDisposed || box.Disposing)
54 | return;
55 | SendMessage(box.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetTime.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 |
19 | */
20 | using System;
21 | using System.Collections.Generic;
22 | using System.Text;
23 | using System.Diagnostics;
24 |
25 | namespace Lidgren.Network
26 | {
27 | ///
28 | /// Time service
29 | ///
30 | public static partial class NetTime
31 | {
32 | ///
33 | /// Given seconds it will output a human friendly readable string (milliseconds if less than 60 seconds)
34 | ///
35 | public static string ToReadable(double seconds)
36 | {
37 | if (seconds > 60)
38 | return TimeSpan.FromSeconds(seconds).ToString();
39 | return (seconds * 1000.0).ToString("N2") + " ms";
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Samples/SamplesCommon/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Windows.Forms;
5 |
6 | namespace SamplesCommon
7 | {
8 | public static class NativeMethods
9 | {
10 | [DllImport("user32.dll", CharSet = CharSet.Auto)]
11 | public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
12 | public const int WM_VSCROLL = 277; // Vertical scroll
13 | public const int SB_BOTTOM = 7; // Scroll to bottom
14 |
15 | [StructLayout(LayoutKind.Sequential)]
16 | public struct PeekMsg
17 | {
18 | public IntPtr hWnd;
19 | public Message msg;
20 | public IntPtr wParam;
21 | public IntPtr lParam;
22 | public uint time;
23 | public System.Drawing.Point p;
24 | }
25 |
26 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously
27 | [DllImport("User32.dll", CharSet = CharSet.Auto)]
28 | public static extern bool PeekMessage(out PeekMsg msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
29 |
30 | public static bool AppStillIdle
31 | {
32 | get
33 | {
34 | PeekMsg msg;
35 | return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);
36 | }
37 | }
38 |
39 | public static void AppendText(RichTextBox box, string line)
40 | {
41 | if (box == null || box.IsDisposed)
42 | return;
43 | try
44 | {
45 | box.AppendText(line + Environment.NewLine);
46 | ScrollRichTextBox(box);
47 | }
48 | catch
49 | {
50 | }
51 | }
52 |
53 | public static void ScrollRichTextBox(RichTextBox box)
54 | {
55 | if (box == null || box.IsDisposed || box.Disposing)
56 | return;
57 | SendMessage(box.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetReliableSequencedReceiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal sealed class NetReliableSequencedReceiver : NetReceiverChannelBase
6 | {
7 | private int m_windowStart;
8 | private int m_windowSize;
9 |
10 | public NetReliableSequencedReceiver(NetConnection connection, int windowSize)
11 | : base(connection)
12 | {
13 | m_windowSize = windowSize;
14 | }
15 |
16 | private void AdvanceWindow()
17 | {
18 | m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
19 | }
20 |
21 | internal override void ReceiveMessage(NetIncomingMessage message)
22 | {
23 | int nr = message.m_sequenceNumber;
24 |
25 | int relate = NetUtility.RelativeSequenceNumber(nr, m_windowStart);
26 |
27 | // ack no matter what
28 | m_connection.QueueAck(message.m_receivedMessageType, nr);
29 |
30 | if (relate == 0)
31 | {
32 | // Log("Received message #" + message.SequenceNumber + " right on time");
33 |
34 | //
35 | // excellent, right on time
36 | //
37 |
38 | AdvanceWindow();
39 | m_peer.ReleaseMessage(message);
40 | return;
41 | }
42 |
43 | if (relate < 0)
44 | {
45 | m_connection.m_statistics.MessageDropped();
46 | m_peer.LogVerbose("Received message #" + message.m_sequenceNumber + " DROPPING LATE or DUPE");
47 | return;
48 | }
49 |
50 | // relate > 0 = early message
51 | if (relate > m_windowSize)
52 | {
53 | // too early message!
54 | m_connection.m_statistics.MessageDropped();
55 | m_peer.LogDebug("Received " + message + " TOO EARLY! Expected " + m_windowStart);
56 | return;
57 | }
58 |
59 | // ok
60 | m_windowStart = (m_windowStart + relate) % NetConstants.NumSequenceNumbers;
61 | m_peer.ReleaseMessage(message);
62 | return;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Lidgren.Network;
4 |
5 | namespace EncryptionClient
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | var config = new NetPeerConfiguration("enctest");
12 | var client = new NetClient(config);
13 | client.Start();
14 |
15 | System.Threading.Thread.Sleep(100); // give server time to start up
16 |
17 | client.Connect("localhost", 14242);
18 |
19 | var encryption = new NetAESEncryption(client, "Hallonpalt");
20 |
21 | // loop forever
22 | while (true)
23 | {
24 | // read messages
25 | var inc = client.ReadMessage();
26 | if (inc != null)
27 | {
28 | switch (inc.MessageType)
29 | {
30 | case NetIncomingMessageType.DebugMessage:
31 | case NetIncomingMessageType.WarningMessage:
32 | case NetIncomingMessageType.VerboseDebugMessage:
33 | case NetIncomingMessageType.ErrorMessage:
34 | Console.WriteLine(inc.ReadString());
35 | break;
36 | case NetIncomingMessageType.StatusChanged:
37 | var status = (NetConnectionStatus)inc.ReadByte();
38 | Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
39 | break;
40 | }
41 | }
42 |
43 | // if we're connected, get input and send
44 | if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected)
45 | {
46 | Console.WriteLine("Type a message:");
47 | var input = Console.ReadLine();
48 |
49 | var msg = client.CreateMessage();
50 | msg.Write(input);
51 | encryption.Encrypt(msg);
52 |
53 | var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
54 | Console.WriteLine("Message sent: " + ok);
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetPeerStatus.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 |
19 | */
20 | using System;
21 |
22 | namespace Lidgren.Network
23 | {
24 | ///
25 | /// Status for a NetPeer instance
26 | ///
27 | public enum NetPeerStatus
28 | {
29 | ///
30 | /// NetPeer is not running; socket is not bound
31 | ///
32 | NotRunning = 0,
33 |
34 | ///
35 | /// NetPeer is in the process of starting up
36 | ///
37 | Starting = 1,
38 |
39 | ///
40 | /// NetPeer is bound to socket and listening for packets
41 | ///
42 | Running = 2,
43 |
44 | ///
45 | /// Shutdown has been requested and will be executed shortly
46 | ///
47 | ShutdownRequested = 3,
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Server/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 |
6 | namespace Server
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");
13 | config.MaximumConnections = 1;
14 | config.Port = 14242;
15 | config.PingInterval = 2.0f;
16 | config.ConnectionTimeout = 2.0f;
17 | var server = new NetServer(config);
18 |
19 | server.Start();
20 |
21 | while (true)
22 | {
23 | NetIncomingMessage msg;
24 | while ((msg = server.ReadMessage()) != null)
25 | {
26 | switch (msg.MessageType)
27 | {
28 | case NetIncomingMessageType.StatusChanged:
29 | var status = (NetConnectionStatus)msg.ReadByte();
30 | var reason = msg.ReadString();
31 | Console.WriteLine("New status: " + status + " (" + reason + ")");
32 | break;
33 | case NetIncomingMessageType.WarningMessage:
34 | case NetIncomingMessageType.VerboseDebugMessage:
35 | case NetIncomingMessageType.ErrorMessage:
36 | case NetIncomingMessageType.DebugMessage:
37 |
38 | var str = msg.ReadString();
39 | if (str.StartsWith("Malformed packet; stated") ||
40 | str.StartsWith("Received unhandled library message") ||
41 | str.StartsWith("Unexpected NetMessageType"))
42 | break; // we'll get a bunch of these and we're fine with that
43 |
44 | Console.WriteLine(msg.MessageType + ": " + str);
45 | break;
46 | case NetIncomingMessageType.Data:
47 | Console.WriteLine("Received " + msg.LengthBits + " bits of data");
48 | break;
49 | case NetIncomingMessageType.UnconnectedData:
50 | Console.WriteLine("Received " + msg.LengthBits + " bits of unconnected data");
51 | break;
52 | default:
53 | Console.WriteLine("Received " + msg.MessageType);
54 | break;
55 | }
56 | }
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/UnitTests/BitVectorTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Lidgren.Network;
3 |
4 | namespace UnitTests
5 | {
6 | public static class BitVectorTests
7 | {
8 | public static void Run()
9 | {
10 | NetBitVector v = new NetBitVector(256);
11 | for (int i = 0; i < 256; i++)
12 | {
13 | v.Clear();
14 | if (i > 42 && i < 65)
15 | v = new NetBitVector(256);
16 |
17 | if (!v.IsEmpty())
18 | throw new NetException("bit vector fail 1");
19 |
20 | v.Set(i, true);
21 |
22 | if (v.Get(i) == false)
23 | throw new NetException("bit vector fail 2");
24 |
25 | if (v.IsEmpty())
26 | throw new NetException("bit vector fail 3");
27 |
28 | if (i != 79 && v.Get(79) == true)
29 | throw new NetException("bit vector fail 4");
30 |
31 | int f = v.GetFirstSetIndex();
32 | if (f != i)
33 | throw new NetException("bit vector fail 4");
34 | }
35 |
36 | /*
37 | v = new NetBitVector(9);
38 | v.Clear();
39 | v.Set(3, true);
40 | if (v.ToString() != "[000001000]")
41 | throw new NetException("NetBitVector.RotateDown failed");
42 | v.RotateDown();
43 | if (v.Get(3) == true || v.Get(2) == false || v.Get(4) == true)
44 | throw new NetException("NetBitVector.RotateDown failed 2");
45 | if (v.ToString() != "[000000100]")
46 | throw new NetException("NetBitVector.RotateDown failed 3");
47 |
48 | v.Set(0, true);
49 | v.RotateDown();
50 | if (v.ToString() != "[100000010]")
51 | throw new NetException("NetBitVector.RotateDown failed 4");
52 |
53 | v = new NetBitVector(38);
54 | v.Set(0, true);
55 | v.Set(1, true);
56 | v.Set(31, true);
57 |
58 | if (v.ToString() != "[00000010000000000000000000000000000011]")
59 | throw new NetException("NetBitVector.RotateDown failed 5");
60 |
61 | v.RotateDown();
62 |
63 | if (v.ToString() != "[10000001000000000000000000000000000001]")
64 | throw new NetException("NetBitVector.RotateDown failed 5");
65 | */
66 |
67 | Console.WriteLine("NetBitVector tests OK");
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionClient", "EncryptionClient\EncryptionClient.csproj", "{CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionServer", "EncryptionServer\EncryptionServer.csproj", "{C97A1420-D706-4446-AC8A-3A88ABDC1F0F}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Client.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ManyClients
2 | {
3 | partial class Client
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.SuspendLayout();
33 | //
34 | // button1
35 | //
36 | this.button1.Location = new System.Drawing.Point(82, 21);
37 | this.button1.Name = "button1";
38 | this.button1.Size = new System.Drawing.Size(106, 23);
39 | this.button1.TabIndex = 0;
40 | this.button1.Text = "Send message";
41 | this.button1.UseVisualStyleBackColor = true;
42 | this.button1.Click += new System.EventHandler(this.button1_Click);
43 | //
44 | // Client
45 | //
46 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
47 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
48 | this.ClientSize = new System.Drawing.Size(264, 69);
49 | this.Controls.Add(this.button1);
50 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
51 | this.Name = "Client";
52 | this.Text = "Client";
53 | this.ResumeLayout(false);
54 |
55 | }
56 |
57 | #endregion
58 |
59 | private System.Windows.Forms.Button button1;
60 | }
61 | }
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MSServer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Lidgren.Network;
5 | using MSCommon;
6 | using System.Net;
7 |
8 | namespace MSServer
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);
15 |
16 | NetPeerConfiguration config = new NetPeerConfiguration("game");
17 | config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
18 | config.Port = 14242;
19 |
20 | NetServer server = new NetServer(config);
21 | server.Start();
22 |
23 | Console.WriteLine("Server started; waiting 5 seconds...");
24 | System.Threading.Thread.Sleep(5000);
25 |
26 | var lastRegistered = -60.0f;
27 |
28 | while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
29 | {
30 | // (re-)register periodically with master server
31 | if (NetTime.Now > lastRegistered + 60)
32 | {
33 | // register with master server
34 | NetOutgoingMessage regMsg = server.CreateMessage();
35 | regMsg.Write((byte)MasterServerMessageType.RegisterHost);
36 | IPAddress mask;
37 | IPAddress adr = NetUtility.GetMyAddress(out mask);
38 | regMsg.Write(server.UniqueIdentifier);
39 | regMsg.Write(new IPEndPoint(adr, 14242));
40 | Console.WriteLine("Sending registration to master server");
41 | server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
42 | lastRegistered = (float)NetTime.Now;
43 | }
44 |
45 | NetIncomingMessage inc;
46 | while ((inc = server.ReadMessage()) != null)
47 | {
48 | switch (inc.MessageType)
49 | {
50 | case NetIncomingMessageType.VerboseDebugMessage:
51 | case NetIncomingMessageType.DebugMessage:
52 | case NetIncomingMessageType.WarningMessage:
53 | case NetIncomingMessageType.ErrorMessage:
54 | Console.WriteLine(inc.ReadString());
55 | break;
56 | }
57 | }
58 |
59 | System.Threading.Thread.Sleep(1);
60 | }
61 |
62 | Console.ReadKey();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | using SamplesCommon;
6 |
7 | using Lidgren.Network;
8 |
9 | namespace UnconnectedSample
10 | {
11 | static class Program
12 | {
13 | public static Form1 MainForm;
14 | public static NetPeer Peer;
15 |
16 | [STAThread]
17 | static void Main()
18 | {
19 | Application.EnableVisualStyles();
20 | Application.SetCompatibleTextRenderingDefault(false);
21 | MainForm = new Form1();
22 |
23 | NetPeerConfiguration config = new NetPeerConfiguration("unconntest");
24 | config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
25 | config.AcceptIncomingConnections = false; // don't accept connections; we're just using unconnected messages in this sample
26 |
27 | Peer = new NetPeer(config);
28 | Peer.Start();
29 |
30 | Application.Idle += new EventHandler(AppLoop);
31 | Application.Run(MainForm);
32 | }
33 |
34 | static void AppLoop(object sender, EventArgs e)
35 | {
36 | while (NativeMethods.AppStillIdle)
37 | {
38 | // read any incoming messages
39 | NetIncomingMessage im;
40 | while((im = Peer.ReadMessage()) != null)
41 | {
42 | switch (im.MessageType)
43 | {
44 | case NetIncomingMessageType.DebugMessage:
45 | case NetIncomingMessageType.VerboseDebugMessage:
46 | case NetIncomingMessageType.WarningMessage:
47 | case NetIncomingMessageType.ErrorMessage:
48 | MainForm.richTextBox1.AppendText(im.ReadString() + Environment.NewLine);
49 | break;
50 | case NetIncomingMessageType.UnconnectedData:
51 | MainForm.richTextBox1.AppendText("Received from " + im.SenderEndPoint + ": " + im.ReadString() + Environment.NewLine);
52 | break;
53 | }
54 | Peer.Recycle(im);
55 | }
56 |
57 | System.Threading.Thread.Sleep(1);
58 | }
59 | }
60 |
61 | internal static void Send(string host, int port, string text)
62 | {
63 | NetOutgoingMessage om = Peer.CreateMessage();
64 | om.Write(text);
65 |
66 | Peer.SendUnconnectedMessage(om, host, port);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/StreamingClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Lidgren.Network;
3 | using System.IO;
4 |
5 | namespace FileStreamServer
6 | {
7 | public class StreamingClient
8 | {
9 | private FileStream m_inputStream;
10 | private int m_sentOffset;
11 | private int m_chunkLen;
12 | private byte[] m_tmpBuffer;
13 | private NetConnection m_connection;
14 |
15 | public StreamingClient(NetConnection conn, string fileName)
16 | {
17 | m_connection = conn;
18 | m_inputStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
19 | m_chunkLen = m_connection.Peer.Configuration.MaximumTransmissionUnit - 20;
20 | m_tmpBuffer = new byte[m_chunkLen];
21 | m_sentOffset = 0;
22 | }
23 |
24 | public void Heartbeat()
25 | {
26 | if (m_inputStream == null)
27 | return;
28 |
29 | if (m_connection.CanSendImmediately(NetDeliveryMethod.ReliableOrdered, 1))
30 | {
31 | // send another part of the file!
32 | long remaining = m_inputStream.Length - m_sentOffset;
33 | int sendBytes = (remaining > m_chunkLen ? m_chunkLen : (int)remaining);
34 |
35 | // just assume we can read the whole thing in one Read()
36 | m_inputStream.Read(m_tmpBuffer, 0, sendBytes);
37 |
38 | NetOutgoingMessage om;
39 | if (m_sentOffset == 0)
40 | {
41 | // first message; send length, chunk length and file name
42 | om = m_connection.Peer.CreateMessage(sendBytes + 8);
43 | om.Write((ulong)m_inputStream.Length);
44 | om.Write(Path.GetFileName(m_inputStream.Name));
45 | m_connection.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 1);
46 | }
47 |
48 | om = m_connection.Peer.CreateMessage(sendBytes + 8);
49 | om.Write(m_tmpBuffer, 0, sendBytes);
50 |
51 | m_connection.SendMessage(om, NetDeliveryMethod.ReliableOrdered, 1);
52 | m_sentOffset += sendBytes;
53 |
54 | //Program.Output("Sent " + m_sentOffset + "/" + m_inputStream.Length + " bytes to " + m_connection);
55 |
56 | if (remaining - sendBytes <= 0)
57 | {
58 | m_inputStream.Close();
59 | m_inputStream.Dispose();
60 | m_inputStream = null;
61 | }
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyServer/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ManyServer
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.richTextBox1 = new System.Windows.Forms.RichTextBox();
32 | this.SuspendLayout();
33 | //
34 | // richTextBox1
35 | //
36 | this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
37 | | System.Windows.Forms.AnchorStyles.Left)
38 | | System.Windows.Forms.AnchorStyles.Right)));
39 | this.richTextBox1.Location = new System.Drawing.Point(12, 168);
40 | this.richTextBox1.Name = "richTextBox1";
41 | this.richTextBox1.Size = new System.Drawing.Size(808, 283);
42 | this.richTextBox1.TabIndex = 0;
43 | this.richTextBox1.Text = "";
44 | //
45 | // Form1
46 | //
47 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
48 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
49 | this.ClientSize = new System.Drawing.Size(832, 463);
50 | this.Controls.Add(this.richTextBox1);
51 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
52 | this.Name = "Form1";
53 | this.Text = "Form1";
54 | this.ResumeLayout(false);
55 |
56 | }
57 |
58 | #endregion
59 |
60 | public System.Windows.Forms.RichTextBox richTextBox1;
61 |
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/Lidgren.Network/Encryption/NetCryptoProviderBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Security.Cryptography;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public abstract class NetCryptoProviderBase : NetEncryption
8 | {
9 | protected SymmetricAlgorithm m_algorithm;
10 |
11 | public NetCryptoProviderBase(NetPeer peer, SymmetricAlgorithm algo)
12 | : base(peer)
13 | {
14 | m_algorithm = algo;
15 | m_algorithm.GenerateKey();
16 | m_algorithm.GenerateIV();
17 | }
18 |
19 | public override void SetKey(byte[] data, int offset, int count)
20 | {
21 | int len = m_algorithm.Key.Length;
22 | var key = new byte[len];
23 | for (int i = 0; i < len; i++)
24 | key[i] = data[offset + (i % count)];
25 | m_algorithm.Key = key;
26 |
27 | len = m_algorithm.IV.Length;
28 | key = new byte[len];
29 | for (int i = 0; i < len; i++)
30 | key[len - 1 - i] = data[offset + (i % count)];
31 | m_algorithm.IV = key;
32 | }
33 |
34 | public override bool Encrypt(NetOutgoingMessage msg)
35 | {
36 | int unEncLenBits = msg.LengthBits;
37 |
38 | var ms = new MemoryStream();
39 | var cs = new CryptoStream(ms, m_algorithm.CreateEncryptor(), CryptoStreamMode.Write);
40 | cs.Write(msg.m_data, 0, msg.LengthBytes);
41 | cs.Close();
42 |
43 | // get results
44 | var arr = ms.ToArray();
45 | ms.Close();
46 |
47 | msg.EnsureBufferSize((arr.Length + 4) * 8);
48 | msg.LengthBits = 0; // reset write pointer
49 | msg.Write((uint)unEncLenBits);
50 | msg.Write(arr);
51 | msg.LengthBits = (arr.Length + 4) * 8;
52 |
53 | return true;
54 | }
55 |
56 | public override bool Decrypt(NetIncomingMessage msg)
57 | {
58 | int unEncLenBits = (int)msg.ReadUInt32();
59 |
60 | var ms = new MemoryStream(msg.m_data, 4, msg.LengthBytes - 4);
61 | var cs = new CryptoStream(ms, m_algorithm.CreateDecryptor(), CryptoStreamMode.Read);
62 |
63 | var byteLen = NetUtility.BytesToHoldBits(unEncLenBits);
64 | var result = m_peer.GetStorage(byteLen);
65 | cs.Read(result, 0, byteLen);
66 | cs.Close();
67 |
68 | // TODO: recycle existing msg
69 |
70 | msg.m_data = result;
71 | msg.m_bitLength = unEncLenBits;
72 | msg.m_readPosition = 0;
73 |
74 | return true;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 | using Lidgren.Network;
10 |
11 | namespace ManyClients
12 | {
13 | public partial class Client : Form
14 | {
15 | private const double c_sendFrequency = 1.0;
16 |
17 | public NetClient Net;
18 |
19 | private double m_lastSent;
20 |
21 | public Client()
22 | {
23 | InitializeComponent();
24 |
25 | NetPeerConfiguration config = new NetPeerConfiguration("many");
26 | #if DEBUG
27 | config.SimulatedLoss = 0.02f;
28 | #endif
29 | Net = new NetClient(config);
30 | Net.Start();
31 | Net.Connect("localhost", 14242);
32 | }
33 |
34 | protected override void OnClosed(EventArgs e)
35 | {
36 | Net.Shutdown("closed");
37 | }
38 |
39 | internal void Shutdown()
40 | {
41 | Net.Shutdown("bye");
42 | }
43 |
44 | internal void Heartbeat()
45 | {
46 | NetIncomingMessage inc;
47 | while ((inc = Net.ReadMessage()) != null)
48 | {
49 | switch (inc.MessageType)
50 | {
51 | case NetIncomingMessageType.StatusChanged:
52 | NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
53 | this.Text = status.ToString();
54 | break;
55 | case NetIncomingMessageType.ErrorMessage:
56 | this.Text = inc.ReadString();
57 | break;
58 | }
59 | }
60 |
61 | // send message?
62 | if (NetTime.Now > m_lastSent + c_sendFrequency)
63 | {
64 | var om = Net.CreateMessage();
65 | om.Write("Hi!");
66 | Net.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
67 | m_lastSent = NetTime.Now;
68 |
69 | // also update title
70 | #if DEBUG
71 | this.Text = Net.Statistics.SentBytes + " bytes sent; " + Net.Statistics.ReceivedBytes + " bytes received";
72 | #else
73 | string str = Net.ServerConnection == null ? "No connection" : Net.ServerConnection.Status.ToString();
74 | if (this.Text != str)
75 | this.Text = str;
76 | #endif
77 | }
78 | }
79 |
80 | private void button1_Click(object sender, EventArgs e)
81 | {
82 | var om = Net.CreateMessage();
83 | om.Write("Manual hi!");
84 |
85 | Net.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/UnitTests/NetQueueTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Lidgren.Network;
4 |
5 | namespace UnitTests
6 | {
7 | public static class NetQueueTests
8 | {
9 | public static void Run()
10 | {
11 | NetQueue queue = new NetQueue(4);
12 |
13 | queue.Enqueue(1);
14 | queue.Enqueue(2);
15 | queue.Enqueue(3);
16 |
17 | int[] arr = queue.ToArray();
18 | if (arr.Length != 3)
19 | throw new Exception("NetQueue.ToArray failure");
20 | if (arr[0] != 1 || arr[1] != 2 || arr[2] != 3)
21 | throw new Exception("NetQueue.ToArray failure");
22 |
23 | bool ok;
24 | int a;
25 |
26 | if (queue.Contains(4))
27 | throw new Exception("NetQueue Contains failure");
28 |
29 | if (!queue.Contains(2))
30 | throw new Exception("NetQueue Contains failure 2");
31 |
32 | if (queue.Count != 3)
33 | throw new Exception("NetQueue failed");
34 |
35 | ok = queue.TryDequeue(out a);
36 | if (ok == false || a != 1)
37 | throw new Exception("NetQueue failure");
38 |
39 | if (queue.Count != 2)
40 | throw new Exception("NetQueue failed");
41 |
42 | queue.EnqueueFirst(42);
43 | if (queue.Count != 3)
44 | throw new Exception("NetQueue failed");
45 |
46 | ok = queue.TryDequeue(out a);
47 | if (ok == false || a != 42)
48 | throw new Exception("NetQueue failed");
49 |
50 | ok = queue.TryDequeue(out a);
51 | if (ok == false || a != 2)
52 | throw new Exception("NetQueue failed");
53 |
54 | ok = queue.TryDequeue(out a);
55 | if (ok == false || a != 3)
56 | throw new Exception("NetQueue failed");
57 |
58 | ok = queue.TryDequeue(out a);
59 | if (ok == true)
60 | throw new Exception("NetQueue failed");
61 |
62 | ok = queue.TryDequeue(out a);
63 | if (ok == true)
64 | throw new Exception("NetQueue failed");
65 |
66 | queue.Enqueue(78);
67 | if (queue.Count != 1)
68 | throw new Exception("NetQueue failed");
69 |
70 | ok = queue.TryDequeue(out a);
71 | if (ok == false || a != 78)
72 | throw new Exception("NetQueue failed");
73 |
74 | queue.Clear();
75 | if (queue.Count != 0)
76 | throw new Exception("NetQueue.Clear failed");
77 |
78 | int[] arr2 = queue.ToArray();
79 | if (arr2.Length != 0)
80 | throw new Exception("NetQueue.ToArray failure");
81 |
82 | Console.WriteLine("NetQueue tests OK");
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetPeer.Discovery.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Threading;
4 |
5 | #if !__NOIPENDPOINT__
6 | using NetEndPoint = System.Net.IPEndPoint;
7 | #endif
8 |
9 | namespace Lidgren.Network
10 | {
11 | public partial class NetPeer
12 | {
13 | ///
14 | /// Emit a discovery signal to all hosts on your subnet
15 | ///
16 | public void DiscoverLocalPeers(int serverPort)
17 | {
18 | NetOutgoingMessage um = CreateMessage(0);
19 | um.m_messageType = NetMessageType.Discovery;
20 | Interlocked.Increment(ref um.m_recyclingCount);
21 |
22 | m_unsentUnconnectedMessages.Enqueue(new NetTuple(new NetEndPoint(NetUtility.GetBroadcastAddress(), serverPort), um));
23 | }
24 |
25 | ///
26 | /// Emit a discovery signal to a single known host
27 | ///
28 | public bool DiscoverKnownPeer(string host, int serverPort)
29 | {
30 | var address = NetUtility.Resolve(host);
31 | if (address == null)
32 | return false;
33 | DiscoverKnownPeer(new NetEndPoint(address, serverPort));
34 | return true;
35 | }
36 |
37 | ///
38 | /// Emit a discovery signal to a single known host
39 | ///
40 | public void DiscoverKnownPeer(NetEndPoint endPoint)
41 | {
42 | NetOutgoingMessage om = CreateMessage(0);
43 | om.m_messageType = NetMessageType.Discovery;
44 | om.m_recyclingCount = 1;
45 | m_unsentUnconnectedMessages.Enqueue(new NetTuple(endPoint, om));
46 | }
47 |
48 | ///
49 | /// Send a discovery response message
50 | ///
51 | public void SendDiscoveryResponse(NetOutgoingMessage msg, NetEndPoint recipient)
52 | {
53 | if (recipient == null)
54 | throw new ArgumentNullException("recipient");
55 |
56 | if (msg == null)
57 | msg = CreateMessage(0);
58 | else if (msg.m_isSent)
59 | throw new NetException("Message has already been sent!");
60 |
61 | if (msg.LengthBytes >= m_configuration.MaximumTransmissionUnit)
62 | throw new NetException("Cannot send discovery message larger than MTU (currently " + m_configuration.MaximumTransmissionUnit + " bytes)");
63 |
64 | msg.m_messageType = NetMessageType.DiscoveryResponse;
65 | Interlocked.Increment(ref msg.m_recyclingCount);
66 | m_unsentUnconnectedMessages.Enqueue(new NetTuple(recipient, msg));
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/UnitTests/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using Lidgren.Network;
4 | using System.Net;
5 | using System.Net.Sockets;
6 |
7 | namespace UnitTests
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | NetPeerConfiguration config = new NetPeerConfiguration("unittests");
14 | config.EnableUPnP = true;
15 | NetPeer peer = new NetPeer(config);
16 | peer.Start(); // needed for initialization
17 |
18 | Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(peer.UniqueIdentifier));
19 |
20 | ReadWriteTests.Run(peer);
21 |
22 | NetQueueTests.Run();
23 |
24 | MiscTests.Run(peer);
25 |
26 | BitVectorTests.Run();
27 |
28 | EncryptionTests.Run(peer);
29 |
30 | var om = peer.CreateMessage();
31 | peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
32 | try
33 | {
34 | peer.SendUnconnectedMessage(om, new IPEndPoint(IPAddress.Loopback, 14242));
35 | }
36 | catch (NetException nex)
37 | {
38 | if (nex.Message != "This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently")
39 | throw;
40 | }
41 |
42 | peer.Shutdown("bye");
43 |
44 | // read all message
45 | NetIncomingMessage inc = peer.WaitMessage(5000);
46 | while (inc != null)
47 | {
48 | switch (inc.MessageType)
49 | {
50 | case NetIncomingMessageType.DebugMessage:
51 | case NetIncomingMessageType.VerboseDebugMessage:
52 | case NetIncomingMessageType.WarningMessage:
53 | case NetIncomingMessageType.ErrorMessage:
54 | Console.WriteLine("Peer message: " + inc.ReadString());
55 | break;
56 | case NetIncomingMessageType.Error:
57 | throw new Exception("Received error message!");
58 | }
59 |
60 | inc = peer.ReadMessage();
61 | }
62 |
63 | Console.WriteLine("Done");
64 | }
65 |
66 | ///
67 | /// Helper method
68 | ///
69 | public static NetIncomingMessage CreateIncomingMessage(byte[] fromData, int bitLength)
70 | {
71 | NetIncomingMessage inc = (NetIncomingMessage)Activator.CreateInstance(typeof(NetIncomingMessage), true);
72 | typeof(NetIncomingMessage).GetField("m_data", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(inc, fromData);
73 | typeof(NetIncomingMessage).GetField("m_bitLength", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(inc, bitLength);
74 | return inc;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetException.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 | */
19 | using System;
20 | using System.Diagnostics;
21 | using System.Runtime.Serialization;
22 |
23 | namespace Lidgren.Network
24 | {
25 | ///
26 | /// Exception thrown in the Lidgren Network Library
27 | ///
28 | public sealed class NetException : Exception
29 | {
30 | ///
31 | /// NetException constructor
32 | ///
33 | public NetException()
34 | : base()
35 | {
36 | }
37 |
38 | ///
39 | /// NetException constructor
40 | ///
41 | public NetException(string message)
42 | : base(message)
43 | {
44 | }
45 |
46 | ///
47 | /// NetException constructor
48 | ///
49 | public NetException(string message, Exception inner)
50 | : base(message, inner)
51 | {
52 | }
53 |
54 | ///
55 | /// Throws an exception, in DEBUG only, if first parameter is false
56 | ///
57 | [Conditional("DEBUG")]
58 | public static void Assert(bool isOk, string message)
59 | {
60 | if (!isOk)
61 | throw new NetException(message);
62 | }
63 |
64 | ///
65 | /// Throws an exception, in DEBUG only, if first parameter is false
66 | ///
67 | [Conditional("DEBUG")]
68 | public static void Assert(bool isOk)
69 | {
70 | if (!isOk)
71 | throw new NetException();
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/GarbageThrowerSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{CCE7E8B5-4167-464C-9B11-EEB9A4439EC1}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {CCE7E8B5-4167-464C-9B11-EEB9A4439EC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {CCE7E8B5-4167-464C-9B11-EEB9A4439EC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {CCE7E8B5-4167-464C-9B11-EEB9A4439EC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {CCE7E8B5-4167-464C-9B11-EEB9A4439EC1}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}.Release|Any CPU.Build.0 = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/Lidgren.Network/Platform/PlatformConstrained.cs:
--------------------------------------------------------------------------------
1 | #if __CONSTRAINED__ || UNITY_STANDALONE_LINUX || UNITY
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Net;
5 | using System.Security.Cryptography;
6 |
7 | namespace Lidgren.Network
8 | {
9 | public static partial class NetUtility
10 | {
11 | private static byte[] s_randomMacBytes;
12 |
13 | static NetUtility()
14 | {
15 | }
16 |
17 | [CLSCompliant(false)]
18 | public static ulong GetPlatformSeed(int seedInc)
19 | {
20 | ulong seed = (ulong)Environment.TickCount + (ulong)seedInc;
21 | return seed ^ ((ulong)(new object().GetHashCode()) << 32);
22 | }
23 |
24 | ///
25 | /// Gets my local IPv4 address (not necessarily external) and subnet mask
26 | ///
27 | public static IPAddress GetMyAddress(out IPAddress mask)
28 | {
29 | mask = null;
30 | #if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS || UNITY
31 | try
32 | {
33 | if (!(UnityEngine.Application.internetReachability == UnityEngine.NetworkReachability.NotReachable))
34 | {
35 | return null;
36 | }
37 | return IPAddress.Parse(UnityEngine.Network.player.externalIP);
38 | }
39 | catch // Catch Access Denied errors
40 | {
41 | return null;
42 | }
43 | #endif
44 | return null;
45 | }
46 |
47 | public static byte[] GetMacAddressBytes()
48 | {
49 | if (s_randomMacBytes == null)
50 | {
51 | s_randomMacBytes = new byte[8];
52 | MWCRandom.Instance.NextBytes(s_randomMacBytes);
53 | }
54 | return s_randomMacBytes;
55 | }
56 |
57 | public static IPAddress GetBroadcastAddress()
58 | {
59 | return IPAddress.Broadcast;
60 | }
61 |
62 | public static void Sleep(int milliseconds)
63 | {
64 | System.Threading.Thread.Sleep(milliseconds);
65 | }
66 |
67 | public static IPAddress CreateAddressFromBytes(byte[] bytes)
68 | {
69 | return new IPAddress(bytes);
70 | }
71 |
72 | private static readonly SHA1 s_sha = SHA1.Create();
73 | public static byte[] ComputeSHAHash(byte[] bytes, int offset, int count)
74 | {
75 | return s_sha.ComputeHash(bytes, offset, count);
76 | }
77 | }
78 |
79 | public static partial class NetTime
80 | {
81 | private static readonly long s_timeInitialized = Environment.TickCount;
82 |
83 | ///
84 | /// Get number of seconds since the application started
85 | ///
86 | public static double Now { get { return (double)((uint)Environment.TickCount - s_timeInitialized) / 1000.0; } }
87 | }
88 | }
89 | #endif
90 |
--------------------------------------------------------------------------------
/Lidgren.Network/Platform/PlatformAndroid.cs:
--------------------------------------------------------------------------------
1 | #if __ANDROID__
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Security.Cryptography;
5 | using System.Net;
6 |
7 | namespace Lidgren.Network
8 | {
9 | public static partial class NetUtility
10 | {
11 | private static byte[] s_randomMacBytes;
12 |
13 | static NetUtility()
14 | {
15 | }
16 |
17 | [CLSCompliant(false)]
18 | public static ulong GetPlatformSeed(int seedInc)
19 | {
20 | ulong seed = (ulong)Environment.TickCount + (ulong)seedInc;
21 | return seed ^ ((ulong)(new object().GetHashCode()) << 32);
22 | }
23 |
24 | ///
25 | /// Gets my local IPv4 address (not necessarily external) and subnet mask
26 | ///
27 | public static IPAddress GetMyAddress(out IPAddress mask)
28 | {
29 | mask = null;
30 | try
31 | {
32 | Android.Net.Wifi.WifiManager wifi = (Android.Net.Wifi.WifiManager)Android.App.Application.Context.GetSystemService(Android.App.Activity.WifiService);
33 | if (!wifi.IsWifiEnabled)
34 | return null;
35 |
36 | var dhcp = wifi.DhcpInfo;
37 | int addr = dhcp.IpAddress;
38 | byte[] quads = new byte[4];
39 | for (int k = 0; k < 4; k++)
40 | quads[k] = (byte)((addr >> k * 8) & 0xFF);
41 | return new IPAddress(quads);
42 | }
43 | catch // Catch Access Denied errors
44 | {
45 | return null;
46 | }
47 | }
48 |
49 | public static byte[] GetMacAddressBytes()
50 | {
51 | if (s_randomMacBytes == null)
52 | {
53 | s_randomMacBytes = new byte[8];
54 | MWCRandom.Instance.NextBytes(s_randomMacBytes);
55 | }
56 | return s_randomMacBytes;
57 | }
58 |
59 | public static void Sleep(int milliseconds)
60 | {
61 | System.Threading.Thread.Sleep(milliseconds);
62 | }
63 |
64 | public static IPAddress GetBroadcastAddress()
65 | {
66 | return IPAddress.Broadcast;
67 | }
68 |
69 | public static IPAddress CreateAddressFromBytes(byte[] bytes)
70 | {
71 | return new IPAddress(bytes);
72 | }
73 |
74 | private static readonly SHA1 s_sha = SHA1.Create();
75 | public static byte[] ComputeSHAHash(byte[] bytes, int offset, int count)
76 | {
77 | return s_sha.ComputeHash(bytes, offset, count);
78 | }
79 | }
80 |
81 | public static partial class NetTime
82 | {
83 | private static readonly long s_timeInitialized = Environment.TickCount;
84 |
85 | ///
86 | /// Get number of seconds since the application started
87 | ///
88 | public static double Now { get { return (double)((uint)Environment.TickCount - s_timeInitialized) / 1000.0; } }
89 | }
90 | }
91 | #endif
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/ManySample/ManyClients/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ManyClients
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.label1 = new System.Windows.Forms.Label();
32 | this.button1 = new System.Windows.Forms.Button();
33 | this.SuspendLayout();
34 | //
35 | // label1
36 | //
37 | this.label1.AutoSize = true;
38 | this.label1.Location = new System.Drawing.Point(12, 9);
39 | this.label1.Name = "label1";
40 | this.label1.Size = new System.Drawing.Size(38, 13);
41 | this.label1.TabIndex = 0;
42 | this.label1.Text = "label1";
43 | //
44 | // button1
45 | //
46 | this.button1.Location = new System.Drawing.Point(63, 44);
47 | this.button1.Name = "button1";
48 | this.button1.Size = new System.Drawing.Size(158, 41);
49 | this.button1.TabIndex = 1;
50 | this.button1.Text = "Create new client";
51 | this.button1.UseVisualStyleBackColor = true;
52 | this.button1.Click += new System.EventHandler(this.button1_Click);
53 | //
54 | // Form1
55 | //
56 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
57 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
58 | this.ClientSize = new System.Drawing.Size(270, 97);
59 | this.Controls.Add(this.button1);
60 | this.Controls.Add(this.label1);
61 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
62 | this.Name = "Form1";
63 | this.Text = "Form1";
64 | this.ResumeLayout(false);
65 | this.PerformLayout();
66 |
67 | }
68 |
69 | #endregion
70 |
71 | private System.Windows.Forms.Label label1;
72 | private System.Windows.Forms.Button button1;
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetConnectionStatus.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 | */
19 | using System;
20 |
21 | namespace Lidgren.Network
22 | {
23 | ///
24 | /// Status for a NetConnection instance
25 | ///
26 | public enum NetConnectionStatus
27 | {
28 | ///
29 | /// No connection, or attempt, in place
30 | ///
31 | None,
32 |
33 | ///
34 | /// Connect has been sent; waiting for ConnectResponse
35 | ///
36 | InitiatedConnect,
37 |
38 | ///
39 | /// Connect was received, but ConnectResponse hasn't been sent yet
40 | ///
41 | ReceivedInitiation,
42 |
43 | ///
44 | /// Connect was received and ApprovalMessage released to the application; awaiting Approve() or Deny()
45 | ///
46 | RespondedAwaitingApproval, // We got Connect, released ApprovalMessage
47 |
48 | ///
49 | /// Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
50 | ///
51 | RespondedConnect, // we got Connect, sent ConnectResponse
52 |
53 | ///
54 | /// Connected
55 | ///
56 | Connected, // we received ConnectResponse (if initiator) or ConnectionEstablished (if passive)
57 |
58 | ///
59 | /// In the process of disconnecting
60 | ///
61 | Disconnecting,
62 |
63 | ///
64 | /// Disconnected
65 | ///
66 | Disconnected
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/ImageGetter.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace ImageClient
2 | {
3 | partial class ImageGetter
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.pictureBox1 = new System.Windows.Forms.PictureBox();
32 | this.richTextBox1 = new System.Windows.Forms.RichTextBox();
33 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
34 | this.SuspendLayout();
35 | //
36 | // pictureBox1
37 | //
38 | this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
39 | this.pictureBox1.Location = new System.Drawing.Point(12, 134);
40 | this.pictureBox1.Name = "pictureBox1";
41 | this.pictureBox1.Size = new System.Drawing.Size(260, 238);
42 | this.pictureBox1.TabIndex = 0;
43 | this.pictureBox1.TabStop = false;
44 | //
45 | // richTextBox1
46 | //
47 | this.richTextBox1.Location = new System.Drawing.Point(12, 12);
48 | this.richTextBox1.Name = "richTextBox1";
49 | this.richTextBox1.Size = new System.Drawing.Size(562, 116);
50 | this.richTextBox1.TabIndex = 1;
51 | this.richTextBox1.Text = "";
52 | //
53 | // ImageGetter
54 | //
55 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
56 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
57 | this.ClientSize = new System.Drawing.Size(586, 521);
58 | this.Controls.Add(this.richTextBox1);
59 | this.Controls.Add(this.pictureBox1);
60 | this.Name = "ImageGetter";
61 | this.Text = "ImageGetter";
62 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
63 | this.ResumeLayout(false);
64 |
65 | }
66 |
67 | #endregion
68 |
69 | private System.Windows.Forms.PictureBox pictureBox1;
70 | public System.Windows.Forms.RichTextBox richTextBox1;
71 | }
72 | }
--------------------------------------------------------------------------------
/Lidgren.Network/NetConstants.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 | */
19 | using System;
20 |
21 | namespace Lidgren.Network
22 | {
23 | ///
24 | /// All the constants used when compiling the library
25 | ///
26 | internal static class NetConstants
27 | {
28 | internal const int NumTotalChannels = 99;
29 |
30 | internal const int NetChannelsPerDeliveryMethod = 32;
31 |
32 | internal const int NumSequenceNumbers = 1024;
33 |
34 | internal const int HeaderByteSize = 5;
35 |
36 | internal const int UnreliableWindowSize = 128;
37 | internal const int ReliableOrderedWindowSize = 64;
38 | internal const int ReliableSequencedWindowSize = 64;
39 | internal const int DefaultWindowSize = 64;
40 |
41 | internal const int MaxFragmentationGroups = ushort.MaxValue - 1;
42 |
43 | internal const int UnfragmentedMessageHeaderSize = 5;
44 |
45 | ///
46 | /// Number of channels which needs a sequence number to work
47 | ///
48 | internal const int NumSequencedChannels = ((int)NetMessageType.UserReliableOrdered1 + NetConstants.NetChannelsPerDeliveryMethod) - (int)NetMessageType.UserSequenced1;
49 |
50 | ///
51 | /// Number of reliable channels
52 | ///
53 | internal const int NumReliableChannels = ((int)NetMessageType.UserReliableOrdered1 + NetConstants.NetChannelsPerDeliveryMethod) - (int)NetMessageType.UserReliableUnordered;
54 |
55 | internal const string ConnResetMessage = "Connection was reset by remote host";
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using Lidgren.Network;
5 | using SamplesCommon;
6 |
7 | namespace FileStreamServer
8 | {
9 | static class Program
10 | {
11 | private static Form1 s_form;
12 | private static NetServer s_server;
13 | private static string s_fileName;
14 |
15 | [STAThread]
16 | static void Main()
17 | {
18 | Application.EnableVisualStyles();
19 | Application.SetCompatibleTextRenderingDefault(false);
20 | s_form = new Form1();
21 |
22 | NetPeerConfiguration config = new NetPeerConfiguration("filestream");
23 | config.Port = 14242;
24 | s_server = new NetServer(config);
25 |
26 | Application.Idle += new EventHandler(AppLoop);
27 | Application.Run(s_form);
28 |
29 | s_server.Shutdown("Application exiting");
30 | }
31 |
32 | public static void Output(string str)
33 | {
34 | if (s_form != null && s_form.richTextBox1 != null)
35 | NativeMethods.AppendText(s_form.richTextBox1, str);
36 | }
37 |
38 | static void AppLoop(object sender, EventArgs e)
39 | {
40 | while (NativeMethods.AppStillIdle)
41 | {
42 | NetIncomingMessage inc;
43 | while((inc = s_server.ReadMessage()) != null)
44 | {
45 | switch (inc.MessageType)
46 | {
47 | case NetIncomingMessageType.DebugMessage:
48 | case NetIncomingMessageType.WarningMessage:
49 | case NetIncomingMessageType.ErrorMessage:
50 | case NetIncomingMessageType.VerboseDebugMessage:
51 | Output(inc.ReadString());
52 | break;
53 | case NetIncomingMessageType.StatusChanged:
54 | NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
55 | switch (status)
56 | {
57 | case NetConnectionStatus.Connected:
58 | // start streaming to this client
59 | inc.SenderConnection.Tag = new StreamingClient(inc.SenderConnection, s_fileName);
60 | Output("Starting streaming to " + inc.SenderConnection);
61 | break;
62 | default:
63 | Output(inc.SenderConnection + ": " + status + " (" + inc.ReadString() + ")");
64 | break;
65 | }
66 | break;
67 | }
68 | s_server.Recycle(inc);
69 | }
70 |
71 | // stream to all connections
72 | foreach (NetConnection conn in s_server.Connections)
73 | {
74 | StreamingClient client = conn.Tag as StreamingClient;
75 | if (client != null)
76 | client.Heartbeat();
77 | }
78 |
79 | System.Threading.Thread.Sleep(0);
80 | }
81 | }
82 |
83 | internal static void Start(string filename)
84 | {
85 | s_fileName = filename;
86 | s_server.Start();
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionClient/EncryptionClient.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {CC8B3DBA-3DA6-407F-B659-91AE02BC67D6}
8 | Exe
9 | Properties
10 | EncryptionClient
11 | EncryptionClient
12 | v4.5.1
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | {49ba1c69-6104-41ac-a5d8-b54fa9f696e8}
45 | Lidgren.Network
46 |
47 |
48 |
49 |
56 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/EncryptionSample/EncryptionServer/EncryptionServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C97A1420-D706-4446-AC8A-3A88ABDC1F0F}
8 | Exe
9 | Properties
10 | EncryptionServer
11 | EncryptionServer
12 | v4.5.1
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | {49ba1c69-6104-41ac-a5d8-b54fa9f696e8}
45 | Lidgren.Network
46 |
47 |
48 |
49 |
56 |
--------------------------------------------------------------------------------
/Lidgren.Network.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 14
3 | MinimumVisualStudioVersion = 10.0.40219.1
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{6691874A-1766-4A08-A72A-B1132FAB8E58}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|Mixed Platforms = Debug|Mixed Platforms
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|Mixed Platforms = Release|Mixed Platforms
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
21 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
22 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|x86.ActiveCfg = Debug|Any CPU
23 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
26 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
27 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU
28 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|Any CPU.ActiveCfg = Debug|x86
29 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|Any CPU.Build.0 = Debug|x86
30 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
31 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|Mixed Platforms.Build.0 = Debug|x86
32 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|x86.ActiveCfg = Debug|x86
33 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Debug|x86.Build.0 = Debug|x86
34 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Release|Any CPU.ActiveCfg = Release|x86
35 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Release|Mixed Platforms.ActiveCfg = Release|x86
36 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Release|Mixed Platforms.Build.0 = Release|x86
37 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Release|x86.ActiveCfg = Release|x86
38 | {6691874A-1766-4A08-A72A-B1132FAB8E58}.Release|x86.Build.0 = Release|x86
39 | EndGlobalSection
40 | GlobalSection(SolutionProperties) = preSolution
41 | HideSolutionNode = FALSE
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetPeer.Logging.cs:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2010 Michael Lidgren
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 | and associated documentation files (the "Software"), to deal in the Software without
5 | restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
7 | the Software is furnished to do so, subject to the following conditions:
8 |
9 | The above copyright notice and this permission notice shall be included in all copies or
10 | substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17 | USE OR OTHER DEALINGS IN THE SOFTWARE.
18 | */
19 | using System.Diagnostics;
20 |
21 | namespace Lidgren.Network
22 | {
23 | public partial class NetPeer
24 | {
25 | [Conditional("DEBUG")]
26 | internal void LogVerbose(string message)
27 | {
28 | #if __ANDROID__
29 | Android.Util.Log.WriteLine(Android.Util.LogPriority.Verbose, "", message);
30 | #endif
31 | if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage))
32 | ReleaseMessage(CreateIncomingMessage(NetIncomingMessageType.VerboseDebugMessage, message));
33 | }
34 |
35 | [Conditional("DEBUG")]
36 | internal void LogDebug(string message)
37 | {
38 | #if __ANDROID__
39 | Android.Util.Log.WriteLine(Android.Util.LogPriority.Debug, "", message);
40 | #endif
41 | if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DebugMessage))
42 | ReleaseMessage(CreateIncomingMessage(NetIncomingMessageType.DebugMessage, message));
43 | }
44 |
45 | internal void LogWarning(string message)
46 | {
47 | #if __ANDROID__
48 | Android.Util.Log.WriteLine(Android.Util.LogPriority.Warn, "", message);
49 | #endif
50 | if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.WarningMessage))
51 | ReleaseMessage(CreateIncomingMessage(NetIncomingMessageType.WarningMessage, message));
52 | }
53 |
54 | internal void LogError(string message)
55 | {
56 | #if __ANDROID__
57 | Android.Util.Log.WriteLine(Android.Util.LogPriority.Error, "", message);
58 | #endif
59 | if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.ErrorMessage))
60 | ReleaseMessage(CreateIncomingMessage(NetIncomingMessageType.ErrorMessage, message));
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Documentation/sandcastle-build-project.shfbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 | Debug
7 | AnyCPU
8 | 2.0
9 | {8d1f9f4d-b742-4ee7-ac23-4b0774db3f34}
10 | 1.9.0.0
11 |
13 | Documentation
14 | Documentation
15 | Documentation
16 |
17 | .\
18 | Documentation
19 | en-US
20 |
21 |
22 |
23 | Lidgren Network Library documentation
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Samples/File stream sample/FileStreamServer/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace FileStreamServer
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.richTextBox1 = new System.Windows.Forms.RichTextBox();
33 | this.SuspendLayout();
34 | //
35 | // button1
36 | //
37 | this.button1.Location = new System.Drawing.Point(12, 12);
38 | this.button1.Name = "button1";
39 | this.button1.Size = new System.Drawing.Size(175, 23);
40 | this.button1.TabIndex = 0;
41 | this.button1.Text = "Select file and start serving";
42 | this.button1.UseVisualStyleBackColor = true;
43 | this.button1.Click += new System.EventHandler(this.button1_Click);
44 | //
45 | // richTextBox1
46 | //
47 | this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
48 | | System.Windows.Forms.AnchorStyles.Left)
49 | | System.Windows.Forms.AnchorStyles.Right)));
50 | this.richTextBox1.Location = new System.Drawing.Point(12, 41);
51 | this.richTextBox1.Name = "richTextBox1";
52 | this.richTextBox1.Size = new System.Drawing.Size(531, 193);
53 | this.richTextBox1.TabIndex = 1;
54 | this.richTextBox1.Text = "";
55 | //
56 | // Form1
57 | //
58 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
59 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
60 | this.ClientSize = new System.Drawing.Size(555, 246);
61 | this.Controls.Add(this.richTextBox1);
62 | this.Controls.Add(this.button1);
63 | this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
64 | this.Name = "Form1";
65 | this.Text = "File stream server";
66 | this.ResumeLayout(false);
67 |
68 | }
69 |
70 | #endregion
71 |
72 | private System.Windows.Forms.Button button1;
73 | public System.Windows.Forms.RichTextBox richTextBox1;
74 | }
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetReliableOrderedReceiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Lidgren.Network
4 | {
5 | internal sealed class NetReliableOrderedReceiver : NetReceiverChannelBase
6 | {
7 | private int m_windowStart;
8 | private int m_windowSize;
9 | private NetBitVector m_earlyReceived;
10 | internal NetIncomingMessage[] m_withheldMessages;
11 |
12 | public NetReliableOrderedReceiver(NetConnection connection, int windowSize)
13 | : base(connection)
14 | {
15 | m_windowSize = windowSize;
16 | m_withheldMessages = new NetIncomingMessage[windowSize];
17 | m_earlyReceived = new NetBitVector(windowSize);
18 | }
19 |
20 | private void AdvanceWindow()
21 | {
22 | m_earlyReceived.Set(m_windowStart % m_windowSize, false);
23 | m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
24 | }
25 |
26 | internal override void ReceiveMessage(NetIncomingMessage message)
27 | {
28 | int relate = NetUtility.RelativeSequenceNumber(message.m_sequenceNumber, m_windowStart);
29 |
30 | // ack no matter what
31 | m_connection.QueueAck(message.m_receivedMessageType, message.m_sequenceNumber);
32 |
33 | if (relate == 0)
34 | {
35 | // Log("Received message #" + message.SequenceNumber + " right on time");
36 |
37 | //
38 | // excellent, right on time
39 | //
40 | //m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
41 |
42 | AdvanceWindow();
43 | m_peer.ReleaseMessage(message);
44 |
45 | // release withheld messages
46 | int nextSeqNr = (message.m_sequenceNumber + 1) % NetConstants.NumSequenceNumbers;
47 |
48 | while (m_earlyReceived[nextSeqNr % m_windowSize])
49 | {
50 | message = m_withheldMessages[nextSeqNr % m_windowSize];
51 | NetException.Assert(message != null);
52 |
53 | // remove it from withheld messages
54 | m_withheldMessages[nextSeqNr % m_windowSize] = null;
55 |
56 | m_peer.LogVerbose("Releasing withheld message #" + message);
57 |
58 | m_peer.ReleaseMessage(message);
59 |
60 | AdvanceWindow();
61 | nextSeqNr++;
62 | }
63 |
64 | return;
65 | }
66 |
67 | if (relate < 0)
68 | {
69 | // duplicate
70 | m_connection.m_statistics.MessageDropped();
71 | m_peer.LogVerbose("Received message #" + message.m_sequenceNumber + " DROPPING DUPLICATE");
72 | return;
73 | }
74 |
75 | // relate > 0 = early message
76 | if (relate > m_windowSize)
77 | {
78 | // too early message!
79 | m_connection.m_statistics.MessageDropped();
80 | m_peer.LogDebug("Received " + message + " TOO EARLY! Expected " + m_windowStart);
81 | return;
82 | }
83 |
84 | m_earlyReceived.Set(message.m_sequenceNumber % m_windowSize, true);
85 | m_peer.LogVerbose("Received " + message + " WITHHOLDING, waiting for " + m_windowStart);
86 | m_withheldMessages[message.m_sequenceNumber % m_windowSize] = message;
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | {6691874A-1766-4A08-A72A-B1132FAB8E58}
8 | Exe
9 | Properties
10 | UnitTests
11 | UnitTests
12 | v4.6
13 |
14 |
15 | 512
16 |
17 |
18 | x86
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 | false
27 |
28 |
29 | x86
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 | false
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}
54 | Lidgren.Network
55 |
56 |
57 |
58 |
59 |
60 |
61 |
68 |
--------------------------------------------------------------------------------
/Samples/MasterServerSample/MasterServerSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasterServer", "MasterServer\MasterServer.csproj", "{47E2AC9A-F375-47A7-A4E6-9814D3A2954B}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSClient", "MSClient\MSClient.csproj", "{E4FBEFAB-0D5F-4108-BAA9-E796E14AD6B2}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSCommon", "MSCommon\MSCommon.csproj", "{DCD2BE10-1B14-4C80-8BD6-77A8B1F43346}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSServer", "MSServer\MSServer.csproj", "{BBE12F3E-098F-4C13-842F-A52B86E2611A}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {47E2AC9A-F375-47A7-A4E6-9814D3A2954B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {47E2AC9A-F375-47A7-A4E6-9814D3A2954B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {47E2AC9A-F375-47A7-A4E6-9814D3A2954B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {47E2AC9A-F375-47A7-A4E6-9814D3A2954B}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {E4FBEFAB-0D5F-4108-BAA9-E796E14AD6B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {E4FBEFAB-0D5F-4108-BAA9-E796E14AD6B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {E4FBEFAB-0D5F-4108-BAA9-E796E14AD6B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {E4FBEFAB-0D5F-4108-BAA9-E796E14AD6B2}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {DCD2BE10-1B14-4C80-8BD6-77A8B1F43346}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {DCD2BE10-1B14-4C80-8BD6-77A8B1F43346}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {DCD2BE10-1B14-4C80-8BD6-77A8B1F43346}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {DCD2BE10-1B14-4C80-8BD6-77A8B1F43346}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {BBE12F3E-098F-4C13-842F-A52B86E2611A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {BBE12F3E-098F-4C13-842F-A52B86E2611A}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {BBE12F3E-098F-4C13-842F-A52B86E2611A}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {BBE12F3E-098F-4C13-842F-A52B86E2611A}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | EndGlobal
45 |
--------------------------------------------------------------------------------
/Lidgren.Network/NetBuffer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 |
5 | namespace Lidgren.Network
6 | {
7 | public partial class NetBuffer
8 | {
9 | ///
10 | /// Number of bytes to overallocate for each message to avoid resizing
11 | ///
12 | protected const int c_overAllocateAmount = 4;
13 |
14 | private static readonly Dictionary s_readMethods;
15 | private static readonly Dictionary s_writeMethods;
16 |
17 | internal byte[] m_data;
18 | internal int m_bitLength;
19 | internal int m_readPosition;
20 |
21 | ///
22 | /// Gets or sets the internal data buffer
23 | ///
24 | public byte[] Data
25 | {
26 | get { return m_data; }
27 | set { m_data = value; }
28 | }
29 |
30 | ///
31 | /// Gets or sets the length of the used portion of the buffer in bytes
32 | ///
33 | public int LengthBytes
34 | {
35 | get { return ((m_bitLength + 7) >> 3); }
36 | set
37 | {
38 | m_bitLength = value * 8;
39 | InternalEnsureBufferSize(m_bitLength);
40 | }
41 | }
42 |
43 | ///
44 | /// Gets or sets the length of the used portion of the buffer in bits
45 | ///
46 | public int LengthBits
47 | {
48 | get { return m_bitLength; }
49 | set
50 | {
51 | m_bitLength = value;
52 | InternalEnsureBufferSize(m_bitLength);
53 | }
54 | }
55 |
56 | ///
57 | /// Gets or sets the read position in the buffer, in bits (not bytes)
58 | ///
59 | public long Position
60 | {
61 | get { return (long)m_readPosition; }
62 | set { m_readPosition = (int)value; }
63 | }
64 |
65 | ///
66 | /// Gets the position in the buffer in bytes; note that the bits of the first returned byte may already have been read - check the Position property to make sure.
67 | ///
68 | public int PositionInBytes
69 | {
70 | get { return (int)(m_readPosition / 8); }
71 | }
72 |
73 | static NetBuffer()
74 | {
75 | s_readMethods = new Dictionary();
76 | MethodInfo[] methods = typeof(NetIncomingMessage).GetMethods(BindingFlags.Instance | BindingFlags.Public);
77 | foreach (MethodInfo mi in methods)
78 | {
79 | if (mi.GetParameters().Length == 0 && mi.Name.StartsWith("Read", StringComparison.InvariantCulture) && mi.Name.Substring(4) == mi.ReturnType.Name)
80 | {
81 | s_readMethods[mi.ReturnType] = mi;
82 | }
83 | }
84 |
85 | s_writeMethods = new Dictionary();
86 | methods = typeof(NetOutgoingMessage).GetMethods(BindingFlags.Instance | BindingFlags.Public);
87 | foreach (MethodInfo mi in methods)
88 | {
89 | if (mi.Name.Equals("Write", StringComparison.InvariantCulture))
90 | {
91 | ParameterInfo[] pis = mi.GetParameters();
92 | if (pis.Length == 1)
93 | s_writeMethods[pis[0].ParameterType] = mi;
94 | }
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Samples/LibraryTestSamples/GarbageThrowerSample/Client/Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {6F2BBE07-7D84-4B8B-9882-1556D2C9F79B}
8 | Exe
9 | Properties
10 | Client
11 | Client
12 | v4.5.1
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | {49ba1c69-6104-41ac-a5d8-b54fa9f696e8}
49 | Lidgren.Network
50 |
51 |
52 | {773069da-b66e-4667-adcb-0d215ad8cf3e}
53 | SamplesCommon
54 |
55 |
56 |
57 |
64 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatClient/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatClient.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ChatClient.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Samples/Chat/ChatServer/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ChatServer.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ChatServer.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageClient/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageClient.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ImageClient.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Samples/ImageSample/ImageServer/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ImageServer.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ImageServer.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------