diff --git a/Samples/ImageSample/ImageClient/Form1.Designer.cs b/Samples/ImageSample/ImageClient/Form1.Designer.cs
new file mode 100644
index 0000000..4525eb6
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Form1.Designer.cs
@@ -0,0 +1,87 @@
+namespace ImageClient
+{
+ 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.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBox1
+ //
+ this.textBox1.Location = new System.Drawing.Point(12, 12);
+ this.textBox1.Name = "textBox1";
+ this.textBox1.Size = new System.Drawing.Size(146, 22);
+ this.textBox1.TabIndex = 0;
+ this.textBox1.Text = "localhost";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(164, 12);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(161, 23);
+ this.button1.TabIndex = 1;
+ this.button1.Text = "Spawn imagegetter";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(331, 12);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(129, 23);
+ this.button2.TabIndex = 2;
+ this.button2.Text = "Settings";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(469, 44);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ 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 = "Image client";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox textBox1;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ }
+}
+
diff --git a/Samples/ImageSample/ImageClient/Form1.cs b/Samples/ImageSample/ImageClient/Form1.cs
new file mode 100644
index 0000000..d25420d
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Form1.cs
@@ -0,0 +1,37 @@
+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;
+using Lidgren.Network;
+using SamplesCommon;
+
+namespace ImageClient
+{
+ public partial class Form1 : Form
+ {
+ private NetPeer m_dummyPeer;
+ private NetPeerConfiguration m_config;
+
+ public Form1()
+ {
+ m_config = new NetPeerConfiguration("ImageTransfer");
+ m_dummyPeer = new NetPeer(m_config);
+ InitializeComponent();
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ Program.SpawnGetter(textBox1.Text, m_config);
+ }
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+ NetPeerSettingsWindow win = new NetPeerSettingsWindow("Client settings", m_dummyPeer);
+ win.Show();
+ }
+ }
+}
diff --git a/Samples/ImageSample/ImageClient/Form1.resx b/Samples/ImageSample/ImageClient/Form1.resx
new file mode 100644
index 0000000..ff31a6d
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/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/ImageSample/ImageClient/ImageClient.csproj b/Samples/ImageSample/ImageClient/ImageClient.csproj
new file mode 100644
index 0000000..521d524
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/ImageClient.csproj
@@ -0,0 +1,103 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.21022
+ 2.0
+ {69E64B8C-4736-4334-87BF-DD631A3AD144}
+ WinExe
+ Properties
+ ImageClient
+ ImageClient
+ v3.5
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+ 3.5
+
+
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+ Form
+
+
+ ImageGetter.cs
+
+
+
+
+ Form1.cs
+ Designer
+
+
+ ImageGetter.cs
+ Designer
+
+
+ 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
diff --git a/Samples/ImageSample/ImageClient/ImageGetter.Designer.cs b/Samples/ImageSample/ImageClient/ImageGetter.Designer.cs
new file mode 100644
index 0000000..cdf9e53
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/ImageGetter.Designer.cs
@@ -0,0 +1,72 @@
+namespace ImageClient
+{
+ partial class ImageGetter
+ {
+ ///
+ /// 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.pictureBox1 = new System.Windows.Forms.PictureBox();
+ this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // pictureBox1
+ //
+ this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
+ this.pictureBox1.Location = new System.Drawing.Point(12, 134);
+ this.pictureBox1.Name = "pictureBox1";
+ this.pictureBox1.Size = new System.Drawing.Size(260, 238);
+ this.pictureBox1.TabIndex = 0;
+ this.pictureBox1.TabStop = false;
+ //
+ // richTextBox1
+ //
+ this.richTextBox1.Location = new System.Drawing.Point(12, 12);
+ this.richTextBox1.Name = "richTextBox1";
+ this.richTextBox1.Size = new System.Drawing.Size(562, 116);
+ this.richTextBox1.TabIndex = 1;
+ this.richTextBox1.Text = "";
+ //
+ // ImageGetter
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(586, 521);
+ this.Controls.Add(this.richTextBox1);
+ this.Controls.Add(this.pictureBox1);
+ this.Name = "ImageGetter";
+ this.Text = "ImageGetter";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox pictureBox1;
+ public System.Windows.Forms.RichTextBox richTextBox1;
+ }
+}
\ No newline at end of file
diff --git a/Samples/ImageSample/ImageClient/ImageGetter.cs b/Samples/ImageSample/ImageClient/ImageGetter.cs
new file mode 100644
index 0000000..591457f
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/ImageGetter.cs
@@ -0,0 +1,158 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+using Lidgren.Network;
+using SamplesCommon;
+
+namespace ImageClient
+{
+ public partial class ImageGetter : Form
+ {
+ public NetClient Client;
+ public byte[] Buffer = new byte[990];
+ public bool[] ReceivedSegments;
+ public int NumReceivedSegments;
+
+ public ImageGetter(string host, NetPeerConfiguration copyConfig)
+ {
+ InitializeComponent();
+
+ NetPeerConfiguration config = copyConfig.Clone();
+ config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
+
+ Client = new NetClient(config);
+ Client.Start();
+
+ Client.DiscoverLocalPeers(14242);
+ }
+
+ public void Heartbeat()
+ {
+ NetIncomingMessage inc;
+ while ((inc = Client.ReadMessage()) != null)
+ {
+ switch(inc.MessageType)
+ {
+ case NetIncomingMessageType.DiscoveryResponse:
+ // found server! just connect...
+
+ string serverResponseHello = inc.ReadString();
+
+ // create approval data
+ NetOutgoingMessage approval = Client.CreateMessage();
+ approval.Write(42);
+ approval.Write("secret");
+
+ Client.Connect(inc.SenderEndpoint, approval);
+ break;
+ case NetIncomingMessageType.DebugMessage:
+ case NetIncomingMessageType.VerboseDebugMessage:
+ case NetIncomingMessageType.WarningMessage:
+ case NetIncomingMessageType.ErrorMessage:
+ string str = inc.ReadString();
+ NativeMethods.AppendText(richTextBox1, str);
+ System.IO.File.AppendAllText("C:\\tmp\\clientlog.txt", str + Environment.NewLine);
+ break;
+ case NetIncomingMessageType.StatusChanged:
+ NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
+ string reason = inc.ReadString();
+ NativeMethods.AppendText(richTextBox1, "New status: " + status + " (" + reason + ")");
+ break;
+ case NetIncomingMessageType.Data:
+ // image data, whee!
+ // ineffective but simple data model
+ ushort width = inc.ReadUInt16();
+ ushort height = inc.ReadUInt16();
+ uint segment = inc.ReadVariableUInt32();
+
+ Bitmap bm = pictureBox1.Image as Bitmap;
+ if (bm == null)
+ {
+ bm = new Bitmap(width + 1, height + 1);
+ pictureBox1.Image = bm;
+ this.Size = new System.Drawing.Size(width + 40, height + 60);
+ pictureBox1.SetBounds(12, 12, width, height);
+ }
+ pictureBox1.SuspendLayout();
+
+ int totalBytes = (width * height * 3);
+ if (inc.LengthBytes < totalBytes)
+ {
+ int wholeSegments = totalBytes / 990;
+ int segLen = 990;
+ int remainder = totalBytes - (wholeSegments * inc.LengthBytes);
+ int totalNumberOfSegments = wholeSegments + (remainder > 0 ? 1 : 0);
+ if (segment >= wholeSegments)
+ segLen = remainder; // last segment can be shorter
+
+ if (ReceivedSegments == null)
+ ReceivedSegments = new bool[totalNumberOfSegments];
+ if (ReceivedSegments[segment] == false)
+ {
+ ReceivedSegments[segment] = true;
+ NumReceivedSegments++;
+ if (NumReceivedSegments >= totalNumberOfSegments)
+ {
+ Client.Disconnect("So long and thanks for all the fish!");
+ }
+ }
+
+
+
+ int pixelsAhead = (int)segment * 330;
+
+ int y = pixelsAhead / width;
+ int x = pixelsAhead - (y * width);
+
+ for (int i = 0; i < (segLen / 3); i++)
+ {
+ // set pixel
+ byte r = inc.ReadByte();
+ byte g = inc.ReadByte();
+ byte b = inc.ReadByte();
+ Color col = Color.FromArgb(r, g, b);
+ bm.SetPixel(x, y, col);
+ x++;
+ if (x >= width)
+ {
+ x = 0;
+ y++;
+ }
+ }
+ }
+ else
+ {
+
+ for(int y=0;y
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/ImageSample/ImageClient/Program.cs b/Samples/ImageSample/ImageClient/Program.cs
new file mode 100644
index 0000000..6d4463e
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Program.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using SamplesCommon;
+using Lidgren.Network;
+
+namespace ImageClient
+{
+ static class Program
+ {
+ public static Form1 MainForm;
+ public static List Getters = new List();
+
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ MainForm = new Form1();
+
+ Application.Idle += new EventHandler(AppLoop);
+ Application.Run(MainForm);
+ }
+
+ static void AppLoop(object sender, EventArgs e)
+ {
+ while (NativeMethods.AppStillIdle)
+ {
+ foreach (ImageGetter getter in Getters)
+ getter.Heartbeat();
+ System.Threading.Thread.Sleep(1);
+ }
+ }
+
+ internal static void SpawnGetter(string host, NetPeerConfiguration copyConfig)
+ {
+ ImageGetter getter = new ImageGetter(host, copyConfig);
+ Getters.Add(getter);
+ getter.Show();
+ }
+ }
+}
diff --git a/Samples/ImageSample/ImageClient/Properties/AssemblyInfo.cs b/Samples/ImageSample/ImageClient/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9465f55
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/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("ImageClient")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("ImageClient")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[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("8dc39d59-b635-4296-bdab-3a18e2d9f425")]
+
+// 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/ImageSample/ImageClient/Properties/Resources.Designer.cs b/Samples/ImageSample/ImageClient/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..7afb00a
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Properties/Resources.Designer.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ImageClient.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("ImageClient.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/ImageSample/ImageClient/Properties/Resources.resx b/Samples/ImageSample/ImageClient/Properties/Resources.resx
new file mode 100644
index 0000000..ffecec8
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/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/ImageSample/ImageClient/Properties/Settings.Designer.cs b/Samples/ImageSample/ImageClient/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..ff27b62
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ImageClient.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/ImageSample/ImageClient/Properties/Settings.settings b/Samples/ImageSample/ImageClient/Properties/Settings.settings
new file mode 100644
index 0000000..abf36c5
--- /dev/null
+++ b/Samples/ImageSample/ImageClient/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/Samples/ImageSample/ImageSample.sln b/Samples/ImageSample/ImageSample.sln
new file mode 100644
index 0000000..1c74420
--- /dev/null
+++ b/Samples/ImageSample/ImageSample.sln
@@ -0,0 +1,38 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+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
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageServer", "ImageServer\ImageServer.csproj", "{36382EFB-BE9E-45B3-BEC8-E70F65CDF868}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageClient", "ImageClient\ImageClient.csproj", "{69E64B8C-4736-4334-87BF-DD631A3AD144}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {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
+ {36382EFB-BE9E-45B3-BEC8-E70F65CDF868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {36382EFB-BE9E-45B3-BEC8-E70F65CDF868}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {36382EFB-BE9E-45B3-BEC8-E70F65CDF868}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {36382EFB-BE9E-45B3-BEC8-E70F65CDF868}.Release|Any CPU.Build.0 = Release|Any CPU
+ {69E64B8C-4736-4334-87BF-DD631A3AD144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {69E64B8C-4736-4334-87BF-DD631A3AD144}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {69E64B8C-4736-4334-87BF-DD631A3AD144}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {69E64B8C-4736-4334-87BF-DD631A3AD144}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Samples/ImageSample/ImageServer/Form1.Designer.cs b/Samples/ImageSample/ImageServer/Form1.Designer.cs
new file mode 100644
index 0000000..737777a
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Form1.Designer.cs
@@ -0,0 +1,89 @@
+namespace ImageServer
+{
+ 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.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+ this.SuspendLayout();
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(253, 12);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 0;
+ this.button1.Text = "settings";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(12, 12);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(235, 23);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "Select image and start serving";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // 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, 41);
+ this.richTextBox1.Name = "richTextBox1";
+ this.richTextBox1.Size = new System.Drawing.Size(469, 130);
+ this.richTextBox1.TabIndex = 2;
+ this.richTextBox1.Text = "";
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(493, 183);
+ this.Controls.Add(this.richTextBox1);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ 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 = "Server: Not running";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button button2;
+ public System.Windows.Forms.RichTextBox richTextBox1;
+ }
+}
+
diff --git a/Samples/ImageSample/ImageServer/Form1.cs b/Samples/ImageSample/ImageServer/Form1.cs
new file mode 100644
index 0000000..e4b0c65
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Form1.cs
@@ -0,0 +1,46 @@
+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;
+using SamplesCommon;
+
+namespace ImageServer
+{
+ public partial class Form1 : Form
+ {
+ private NetPeerSettingsWindow m_settingsWindow;
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ if (m_settingsWindow == null)
+ {
+ m_settingsWindow = new NetPeerSettingsWindow("Image server settings", Program.Server);
+ m_settingsWindow.Show();
+ }
+ else
+ {
+ m_settingsWindow.Close();
+ m_settingsWindow = null;
+ }
+ }
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Filter = "Image files|*.png;*.jpg;*.jpeg";
+ DialogResult res = dlg.ShowDialog();
+ if (res != DialogResult.OK)
+ return;
+ Program.Start(dlg.FileName);
+ }
+ }
+}
diff --git a/Samples/ImageSample/ImageServer/Form1.resx b/Samples/ImageSample/ImageServer/Form1.resx
new file mode 100644
index 0000000..ff31a6d
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/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/ImageSample/ImageServer/ImageServer.csproj b/Samples/ImageSample/ImageServer/ImageServer.csproj
new file mode 100644
index 0000000..55ced33
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/ImageServer.csproj
@@ -0,0 +1,93 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.21022
+ 2.0
+ {36382EFB-BE9E-45B3-BEC8-E70F65CDF868}
+ WinExe
+ Properties
+ ImageServer
+ ImageServer
+ 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
+ Designer
+
+
+ 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
diff --git a/Samples/ImageSample/ImageServer/Program.cs b/Samples/ImageSample/ImageServer/Program.cs
new file mode 100644
index 0000000..ace4bbf
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Program.cs
@@ -0,0 +1,170 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+using Lidgren.Network;
+using SamplesCommon;
+using System.Drawing;
+
+namespace ImageServer
+{
+ static class Program
+ {
+ public static Form1 MainForm;
+ public static NetServer Server;
+ public static byte[] ImageData;
+ public static int ImageWidth, ImageHeight;
+
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ MainForm = new Form1();
+
+ // create a configuration, use identifier "ImageTransfer" - same as client
+ NetPeerConfiguration config = new NetPeerConfiguration("ImageTransfer");
+ config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
+ config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
+
+ // listen on port 14242
+ config.Port = 14242;
+
+ Server = new NetServer(config);
+
+ System.IO.File.Delete("C:\\tmp\\clientlog.txt");
+ System.IO.File.Delete("C:\\tmp\\serverlog.txt");
+
+ Application.Idle += new EventHandler(AppLoop);
+ Application.Run(MainForm);
+ }
+
+ static void AppLoop(object sender, EventArgs e)
+ {
+ NetIncomingMessage inc;
+
+ while (NativeMethods.AppStillIdle)
+ {
+ // read any pending messages
+ while ((inc = Server.WaitMessage(100)) != null)
+ {
+ switch (inc.MessageType)
+ {
+ case NetIncomingMessageType.DebugMessage:
+ case NetIncomingMessageType.VerboseDebugMessage:
+ case NetIncomingMessageType.WarningMessage:
+ case NetIncomingMessageType.ErrorMessage:
+ // just print any message
+ string str = inc.ReadString();
+ NativeMethods.AppendText(MainForm.richTextBox1, str);
+ System.IO.File.AppendAllText("C:\\tmp\\serverlog.txt", str + Environment.NewLine);
+ break;
+ case NetIncomingMessageType.DiscoveryRequest:
+ NetOutgoingMessage dom = Server.CreateMessage();
+ dom.Write("Kokosboll");
+ Server.SendDiscoveryResponse(dom, inc.SenderEndpoint);
+ break;
+ case NetIncomingMessageType.ConnectionApproval:
+
+ // Here we could check inc.SenderConnection.RemoteEndPoint, deny certain ip
+
+ // check hail data
+ try
+ {
+ int a = inc.ReadInt32();
+ string s = inc.ReadString();
+
+ if (a == 42 && s == "secret")
+ inc.SenderConnection.Approve();
+ else
+ inc.SenderConnection.Deny("Bad approve data, go away!");
+ }
+ catch (NetException)
+ {
+ inc.SenderConnection.Deny("Bad approve data, go away!");
+ }
+ break;
+ case NetIncomingMessageType.StatusChanged:
+ NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
+ NativeMethods.AppendText(MainForm.richTextBox1, "New status: " + status + " (" + inc.ReadString() + ")");
+ if (status == NetConnectionStatus.Connected)
+ {
+ //
+ // A client connected; send the entire image in chunks of 990 bytes
+ //
+ /*
+ uint seg = 0;
+ int ptr = 0;
+ while (ptr < ImageData.Length)
+ {
+ int l = ImageData.Length - ptr > 990 ? 990 : ImageData.Length - ptr;
+ NetOutgoingMessage om = Server.CreateMessage(l);
+ om.Write((ushort)ImageWidth);
+ om.Write((ushort)ImageHeight);
+ om.WriteVariableUInt32(seg++);
+ om.Write(ImageData, ptr, l);
+ ptr += 990;
+
+ Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered, 0);
+ }
+ */
+
+ NetOutgoingMessage om = Server.CreateMessage(ImageData.Length + 5);
+
+ om.Write((ushort)ImageWidth);
+ om.Write((ushort)ImageHeight);
+ om.WriteVariableUInt32(0);
+
+ // send entire as a large message that will be automatically fragmented by the library
+ om.Write(ImageData);
+
+ Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
+
+ // all messages will be sent before disconnect so we can call it here
+ // inc.SenderConnection.Disconnect("Bye bye now");
+ }
+ break;
+ }
+
+ // recycle message to avoid garbage
+ Server.Recycle(inc);
+ }
+ }
+ }
+
+ public static void Start(string filename)
+ {
+ if (Server.Status != NetPeerStatus.NotRunning)
+ {
+ Server.Shutdown("Restarting");
+ System.Threading.Thread.Sleep(100);
+ }
+
+ Server.Start();
+
+ MainForm.Text = "Server: Running";
+
+ // get image size
+ Bitmap bm = Bitmap.FromFile(filename) as Bitmap;
+ ImageWidth = bm.Width;
+ ImageHeight = bm.Height;
+
+ // extract color bytes
+ // very slow method, but small code size
+ ImageData = new byte[3 * ImageWidth * ImageHeight];
+ int ptr = 0;
+ for (int y = 0; y < ImageHeight; y++)
+ {
+ for (int x = 0; x < ImageWidth; x++)
+ {
+ Color color = bm.GetPixel(x, y);
+ ImageData[ptr++] = color.R;
+ ImageData[ptr++] = color.G;
+ ImageData[ptr++] = color.B;
+ }
+ }
+
+ bm.Dispose();
+ }
+ }
+}
diff --git a/Samples/ImageSample/ImageServer/Properties/AssemblyInfo.cs b/Samples/ImageSample/ImageServer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..5b32b04
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/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("ImageServer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("ImageServer")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[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("4c8071cf-f3d6-4d3f-8937-944273b6fb40")]
+
+// 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/ImageSample/ImageServer/Properties/Resources.Designer.cs b/Samples/ImageSample/ImageServer/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..84d02b2
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Properties/Resources.Designer.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ImageServer.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("ImageServer.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/ImageSample/ImageServer/Properties/Resources.resx b/Samples/ImageSample/ImageServer/Properties/Resources.resx
new file mode 100644
index 0000000..ffecec8
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/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/ImageSample/ImageServer/Properties/Settings.Designer.cs b/Samples/ImageSample/ImageServer/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..4008204
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ImageServer.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/ImageSample/ImageServer/Properties/Settings.settings b/Samples/ImageSample/ImageServer/Properties/Settings.settings
new file mode 100644
index 0000000..abf36c5
--- /dev/null
+++ b/Samples/ImageSample/ImageServer/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+