diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample.sln b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample.sln new file mode 100644 index 0000000..27749b5 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnconnectedSample", "UnconnectedSample\UnconnectedSample.csproj", "{2E46BD71-03A0-4698-B91E-C711E299D14E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{AE483C29-042E-4226-BA52-D247CE7676DA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E46BD71-03A0-4698-B91E-C711E299D14E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E46BD71-03A0-4698-B91E-C711E299D14E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E46BD71-03A0-4698-B91E-C711E299D14E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E46BD71-03A0-4698-B91E-C711E299D14E}.Release|Any CPU.Build.0 = Release|Any CPU + {AE483C29-042E-4226-BA52-D247CE7676DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE483C29-042E-4226-BA52-D247CE7676DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE483C29-042E-4226-BA52-D247CE7676DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE483C29-042E-4226-BA52-D247CE7676DA}.Release|Any CPU.Build.0 = Release|Any CPU + {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.Designer.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.Designer.cs new file mode 100644 index 0000000..9ab6850 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.Designer.cs @@ -0,0 +1,151 @@ +namespace UnconnectedSample +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(114, 12); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(202, 22); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "localhost"; + // + // textBox2 + // + this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.textBox2.Location = new System.Drawing.Point(360, 12); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(63, 22); + this.textBox2.TabIndex = 1; + // + // textBox3 + // + this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox3.Location = new System.Drawing.Point(48, 40); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(287, 22); + this.textBox3.TabIndex = 2; + // + // richTextBox1 + // + this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.richTextBox1.Location = new System.Drawing.Point(12, 68); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(411, 151); + this.richTextBox1.TabIndex = 3; + this.richTextBox1.Text = ""; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(96, 13); + this.label1.TabIndex = 4; + this.label1.Text = "Destination host:"; + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(322, 15); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(32, 13); + this.label2.TabIndex = 5; + this.label2.Text = "port:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 43); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(30, 13); + this.label3.TabIndex = 6; + this.label3.Text = "Text:"; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(341, 38); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(82, 23); + this.button1.TabIndex = 7; + this.button1.Text = "Send"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(438, 230); + this.Controls.Add(this.button1); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Name = "Form1"; + this.Text = "Unconnected sample"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button1; + public System.Windows.Forms.RichTextBox richTextBox1; + } +} + diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.cs new file mode 100644 index 0000000..40a7e70 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace UnconnectedSample +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + uint port; + if (UInt32.TryParse(textBox2.Text, out port) == false) + { + MessageBox.Show("Please fill in the port of the target peer"); + return; + } + + Program.Send(textBox1.Text, (int)port, textBox3.Text); + } + } +} diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.resx b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.resx new file mode 100644 index 0000000..ff31a6d --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Program.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Program.cs new file mode 100644 index 0000000..3d225d6 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Program.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +using SamplesCommon; + +using Lidgren.Network; + +namespace UnconnectedSample +{ + static class Program + { + public static Form1 MainForm; + public static NetPeer Peer; + + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + MainForm = new Form1(); + + NetPeerConfiguration config = new NetPeerConfiguration("unconntest"); + config.EnableMessageType(NetIncomingMessageType.UnconnectedData); + config.AcceptIncomingConnections = false; // don't accept connections; we're just using unconnected messages in this sample + + Peer = new NetPeer(config); + Peer.Start(); + + Application.Idle += new EventHandler(AppLoop); + Application.Run(MainForm); + } + + static void AppLoop(object sender, EventArgs e) + { + while (NativeMethods.AppStillIdle) + { + // read any incoming messages + NetIncomingMessage im; + while((im = Peer.ReadMessage()) != null) + { + switch (im.MessageType) + { + case NetIncomingMessageType.DebugMessage: + case NetIncomingMessageType.VerboseDebugMessage: + case NetIncomingMessageType.WarningMessage: + case NetIncomingMessageType.ErrorMessage: + MainForm.richTextBox1.AppendText(im.ReadString() + Environment.NewLine); + break; + case NetIncomingMessageType.UnconnectedData: + MainForm.richTextBox1.AppendText("Received from " + im.SenderEndpoint + ": " + im.ReadString() + Environment.NewLine); + Peer.Recycle(im); + break; + } + } + + System.Threading.Thread.Sleep(1); + } + } + + internal static void Send(string host, int port, string text) + { + NetOutgoingMessage om = Peer.CreateMessage(); + om.Write(text); + + Peer.SendUnconnectedMessage(om, host, port); + } + } +} diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/AssemblyInfo.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..24da8c0 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnconnectedSample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("UnconnectedSample")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ceb2581f-f75c-4549-9f3b-88b6929cfd70")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.Designer.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.Designer.cs new file mode 100644 index 0000000..86c1e7b --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4952 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace UnconnectedSample.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UnconnectedSample.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.resx b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.Designer.cs b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.Designer.cs new file mode 100644 index 0000000..721d945 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4952 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace UnconnectedSample.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.settings b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/UnconnectedSample.csproj b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/UnconnectedSample.csproj new file mode 100644 index 0000000..f82a783 --- /dev/null +++ b/Samples/LibraryTestSamples/UnconnectedSample/UnconnectedSample/UnconnectedSample.csproj @@ -0,0 +1,93 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {2E46BD71-03A0-4698-B91E-C711E299D14E} + WinExe + Properties + UnconnectedSample + UnconnectedSample + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {AE483C29-042E-4226-BA52-D247CE7676DA} + Lidgren.Network + + + {773069DA-B66E-4667-ADCB-0D215AD8CF3E} + SamplesCommon + + + + + \ No newline at end of file