├── .gitignore ├── LICENSE ├── P2PNET.Test ├── Cat.cs ├── Dog.cs ├── FilePart.cs ├── Fish.cs ├── ObjectTests.cs ├── P2PNET.Test.csproj ├── Person.cs ├── Pet.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ └── Settings.settings ├── TransportTests.cs ├── app.config └── packages.config ├── P2PNET.sln ├── P2PNET ├── Exceptions.cs ├── FileLayer │ ├── EventArgs │ │ ├── DebugInfoEventArgs.cs │ │ ├── FileReceivedEventArgs.cs │ │ └── FileTransferEventArgs.cs │ ├── FileManager.cs │ ├── FileReceivedReq.cs │ ├── FileSentReq.cs │ ├── FileTransReq.cs │ └── SendableObjects │ │ ├── FileAck.cs │ │ ├── FileMeta.cs │ │ ├── FilePartObj.cs │ │ ├── FileReqMeta.cs │ │ └── ReqAck.cs ├── ILogger.cs ├── ObjectLayer │ ├── BObject.cs │ ├── EventArgs │ │ └── ObjReceivedEventArgs.cs │ ├── Metadata.cs │ ├── ObjPackage.cs │ ├── ObjectManager.cs │ └── Serializer.cs ├── P2PNET.csproj ├── P2PNET.nuspec ├── Properties │ └── AssemblyInfo.cs ├── TransportLayer │ ├── AbstractStreamUtil.cs │ ├── BaseStation.cs │ ├── BufferedUDPStream.cs │ ├── EventArgs │ │ ├── MsgReceivedEventArgs.cs │ │ ├── PeerChangeEventArgs.cs │ │ └── PeerEventArgs.cs │ ├── Listener.cs │ ├── Peer.cs │ ├── ReadStreamUtil.cs │ ├── TransportManager.cs │ ├── TransportType.cs │ └── WriteStreamUtil.cs └── packages.config ├── README.md └── Samples ├── ObjectSamples └── ObjectSender │ ├── App.config │ ├── Cat.cs │ ├── Dog.cs │ ├── Fish.cs │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── ObjectSender.csproj │ ├── Person.cs │ ├── Pet.cs │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── packages.config ├── TransportSamples ├── AutoDiscovery │ ├── App.config │ ├── AutoDiscovery.csproj │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── HeartBeatManager.cs │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── packages.config ├── MessageProgram │ ├── App.config │ ├── BroadcastProgram.csproj │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── packages.config └── MessageSender │ ├── App.config │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── MessageSender.csproj │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── packages.config └── WorkSpace ├── App.config ├── Cat.cs ├── Dog.cs ├── Fish.cs ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Person.cs ├── Pet.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── WorkSpace.csproj └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 CrazySquid1 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 | -------------------------------------------------------------------------------- /P2PNET.Test/Cat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Cat : Pet 10 | { 11 | public Cat(string petName) : base(petName) 12 | { 13 | this.Type = AnimalType.Cat; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET.Test/Dog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Dog : Pet 10 | { 11 | 12 | public Dog(string petName) : base(petName) 13 | { 14 | this.Type = AnimalType.Dog; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /P2PNET.Test/FilePart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | public class FilePart 10 | { 11 | public byte[] BinaryData { get; set; } 12 | 13 | public int Length; 14 | 15 | public FilePart(byte[] mBinaryData) 16 | { 17 | this.BinaryData = mBinaryData; 18 | this.Length = mBinaryData.Length; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /P2PNET.Test/Fish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Fish : Pet 10 | { 11 | public Fish(string petName) : base(petName) 12 | { 13 | this.Type = AnimalType.Fish; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET.Test/P2PNET.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {067456C0-086C-46A8-B37F-1405717B7BFC} 7 | Library 8 | Properties 9 | P2PNET.Test 10 | P2PNET.Test 11 | v4.5.2 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | true 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 36 | True 37 | 38 | 39 | ..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll 40 | True 41 | 42 | 43 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 44 | True 45 | 46 | 47 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 48 | True 49 | 50 | 51 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 52 | True 53 | 54 | 55 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 56 | True 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | True 69 | True 70 | Settings.settings 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | SettingsSingleFileGenerator 81 | Settings.Designer.cs 82 | 83 | 84 | 85 | 86 | {196653e2-638f-4590-82e6-79387f5b2fb9} 87 | P2PNET 88 | 89 | 90 | 91 | 98 | -------------------------------------------------------------------------------- /P2PNET.Test/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | public class Person : Object 10 | { 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | 14 | public int Age { get; set; } 15 | 16 | public List OwnedPets { get; set; } 17 | 18 | public Person(string firstName, string lastName, int age) 19 | { 20 | this.FirstName = firstName; 21 | this.LastName = lastName; 22 | this.Age = age; 23 | 24 | OwnedPets = new List(); 25 | } 26 | 27 | public void AddPet(Pet newPet) 28 | { 29 | OwnedPets.Add(newPet); 30 | } 31 | 32 | public bool Equals(Person secPerson) 33 | { 34 | if(secPerson == null) 35 | { 36 | Console.WriteLine("person is null"); 37 | return false; 38 | } 39 | if(secPerson.OwnedPets.Count != this.OwnedPets.Count) 40 | { 41 | Console.WriteLine("num of pets different"); 42 | return false; 43 | } 44 | 45 | 46 | for(int i = 0; i < OwnedPets.Count; i++) 47 | { 48 | if(!this.OwnedPets[i].Equals(secPerson.OwnedPets[i])) 49 | { 50 | Console.WriteLine("pet have different values"); 51 | return false; 52 | } 53 | } 54 | 55 | if(secPerson.Age != this.Age || secPerson.FirstName != this.FirstName || secPerson.LastName != this.LastName) 56 | { 57 | Console.WriteLine("people have different values"); 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /P2PNET.Test/Pet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | public enum AnimalType 10 | { 11 | Dog = 0, 12 | Cat = 1, 13 | Fish = 2 14 | } 15 | public class Pet 16 | { 17 | public AnimalType Type { get; set; } 18 | public string Name { get; set; } 19 | 20 | public Pet(string petName) 21 | { 22 | this.Name = petName; 23 | } 24 | 25 | public bool Equals(Pet pet) 26 | { 27 | if(pet.Name == this.Name && pet.Type == this.Type) 28 | { 29 | return true; 30 | } 31 | return false; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /P2PNET.Test/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("P2PNET.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("P2PNET.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 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("067456c0-086c-46a8-b37f-1405717b7bfc")] 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 | -------------------------------------------------------------------------------- /P2PNET.Test/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 P2PNET.Test.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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 | -------------------------------------------------------------------------------- /P2PNET.Test/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /P2PNET.Test/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /P2PNET.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /P2PNET.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P2PNET", "P2PNET\P2PNET.csproj", "{196653E2-638F-4590-82E6-79387F5B2FB9}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{AF8CE42B-D862-4FE8-8D10-2BC1985F4224}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TransportSamples", "TransportSamples", "{5B3B5569-0CC6-4AFA-9AD0-2944912203E2}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectSamples", "ObjectSamples", "{910C45DF-8B68-4660-B1A7-24FF59B497FA}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P2PNET.Test", "P2PNET.Test\P2PNET.Test.csproj", "{067456C0-086C-46A8-B37F-1405717B7BFC}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObjectSender", "Samples\ObjectSamples\ObjectSender\ObjectSender.csproj", "{DEC94D14-4588-4558-93D2-CA04CFF85799}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoDiscovery", "Samples\TransportSamples\AutoDiscovery\AutoDiscovery.csproj", "{C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BroadcastProgram", "Samples\TransportSamples\MessageProgram\BroadcastProgram.csproj", "{D415DD7F-5517-46CB-898B-95387248F33D}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessageSender", "Samples\TransportSamples\MessageSender\MessageSender.csproj", "{6464DA1F-347C-4F10-BA92-E1E441B7AAA7}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Release|Any CPU = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {D415DD7F-5517-46CB-898B-95387248F33D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {D415DD7F-5517-46CB-898B-95387248F33D}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {D415DD7F-5517-46CB-898B-95387248F33D}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {D415DD7F-5517-46CB-898B-95387248F33D}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Release|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(NestedProjects) = preSolution 59 | {5B3B5569-0CC6-4AFA-9AD0-2944912203E2} = {AF8CE42B-D862-4FE8-8D10-2BC1985F4224} 60 | {910C45DF-8B68-4660-B1A7-24FF59B497FA} = {AF8CE42B-D862-4FE8-8D10-2BC1985F4224} 61 | {DEC94D14-4588-4558-93D2-CA04CFF85799} = {910C45DF-8B68-4660-B1A7-24FF59B497FA} 62 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2} 63 | {D415DD7F-5517-46CB-898B-95387248F33D} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2} 64 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2} 65 | EndGlobalSection 66 | EndGlobal 67 | -------------------------------------------------------------------------------- /P2PNET/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace P2PNET 4 | { 5 | public class PeerNotKnown : Exception 6 | { 7 | public PeerNotKnown(string message) : base(message) 8 | { 9 | } 10 | } 11 | public class StreamCannotWrite : Exception 12 | { 13 | public StreamCannotWrite(string message) : base(message) 14 | { 15 | 16 | } 17 | } 18 | 19 | public class NoNetworkInterface : Exception 20 | { 21 | public NoNetworkInterface(string message) : base(message) 22 | { 23 | 24 | } 25 | } 26 | 27 | public class FileNotFound: Exception 28 | { 29 | public FileNotFound(string message) : base(message) 30 | { 31 | 32 | } 33 | } 34 | 35 | public class FileTransitionError : Exception 36 | { 37 | public FileTransitionError(string message) : base(message) 38 | { 39 | 40 | } 41 | } 42 | 43 | public class LowLevelTransitionError : Exception 44 | { 45 | public LowLevelTransitionError(string message) : base(message) 46 | { 47 | 48 | } 49 | } 50 | 51 | public class FileBoundaryException : Exception 52 | { 53 | public FileBoundaryException(string message) : base(message) 54 | { 55 | 56 | } 57 | } 58 | 59 | public class InvalidMessage : Exception 60 | { 61 | public InvalidMessage(string message) : base(message) 62 | { 63 | 64 | } 65 | } 66 | 67 | public class DeserializingException : Exception 68 | { 69 | public DeserializingException(string message) : base(message) 70 | { 71 | 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/EventArgs/DebugInfoEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace P2PNET.FileLayer.EventArgs 2 | { 3 | public class DebugInfoEventArgs : System.EventArgs 4 | { 5 | public string Msg { get; } 6 | public DebugInfoEventArgs(string msg) 7 | { 8 | this.Msg = msg; 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /P2PNET/FileLayer/EventArgs/FileReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.EventArgs 8 | { 9 | public class FileReceivedEventArgs : System.EventArgs 10 | { 11 | //constructor 12 | public FileReceivedEventArgs() 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/EventArgs/FileTransferEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.EventArgs 8 | { 9 | public enum TransDirrection 10 | { 11 | sending, 12 | receiving 13 | } 14 | public class FileTransferEventArgs : System.EventArgs 15 | { 16 | public TransDirrection Dirrection { get; } 17 | public string FileName { get; } 18 | public long FileLength { get; } 19 | public long BytesProcessed { get; } 20 | public float Percent 21 | { 22 | get 23 | { 24 | return (float)BytesProcessed / FileLength; 25 | } 26 | } 27 | 28 | //constructor 29 | public FileTransferEventArgs(FileTransReq fileTrans, TransDirrection mDir) 30 | { 31 | this.FileLength = fileTrans.FileDetails.FileSize; 32 | this.BytesProcessed = fileTrans.BytesProcessed; 33 | this.FileName = fileTrans.FileDetails.FileName; 34 | this.Dirrection = mDir; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/FileReceivedReq.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.FileLayer.SendableObjects; 2 | using PCLStorage; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace P2PNET.FileLayer 11 | { 12 | public class FileReceiveReq 13 | { 14 | //for identification FileReceiveReq 15 | public string SenderIpAddress { get; } 16 | 17 | private List fileTransReqs; 18 | 19 | 20 | //constructor 21 | public FileReceiveReq(List mFileTransReqs, string mIpAddress) 22 | { 23 | this.fileTransReqs = mFileTransReqs; 24 | this.SenderIpAddress = mIpAddress; 25 | } 26 | 27 | 28 | public async Task WriteFilePartToFile(FilePartObj receivedFilePart) 29 | { 30 | FileTransReq fileTrans = GetFileTransReqFromFileMeta(receivedFilePart.FileMetadata); 31 | 32 | //validate packet recieved 33 | bool isValid = ValidFilePart(receivedFilePart); 34 | if(!isValid) 35 | { 36 | throw new FileTransitionError("file part received is not valided for this peer."); 37 | } 38 | 39 | //valid file part 40 | byte[] buffer = receivedFilePart.FileData; 41 | await fileTrans.WriteBytes(buffer); 42 | } 43 | 44 | public FileTransReq GetFileTransReqFromFileMeta(FileMeta mFileMeta) 45 | { 46 | //collect info to identify file transfer object 47 | string fileName = mFileMeta.FileName; 48 | string filePath = mFileMeta.FilePath; 49 | foreach(FileTransReq fileTrans in fileTransReqs) 50 | { 51 | if(fileTrans.FileDetails.FileName == fileName && fileTrans.FileDetails.FilePath == filePath) 52 | { 53 | return fileTrans; 54 | } 55 | 56 | } 57 | 58 | //can't find file transfer object 59 | return null; 60 | } 61 | 62 | private bool ValidFilePart(FilePartObj filePart) 63 | { 64 | if(filePart == null) 65 | { 66 | return false; 67 | } 68 | 69 | //TODO 70 | return true; 71 | } 72 | 73 | public async Task CloseRequest() 74 | { 75 | foreach (FileTransReq fileTrans in fileTransReqs) 76 | { 77 | await fileTrans.CloseFileStream(); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/FileSentReq.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.FileLayer.EventArgs; 2 | using P2PNET.FileLayer.SendableObjects; 3 | using P2PNET.ObjectLayer; 4 | using PCLStorage; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace P2PNET.FileLayer 13 | { 14 | public class FileSentReq 15 | { 16 | //for identification FileSentReq 17 | public string targetIpAddress { get; } 18 | 19 | public List FileTransReqs { get; } 20 | private int bufferSize; 21 | 22 | //constructor 23 | public FileSentReq(List mFileTransReqs, int mBufferSize, string mIpAddress) 24 | { 25 | this.bufferSize = mBufferSize; 26 | this.FileTransReqs = mFileTransReqs; 27 | this.targetIpAddress = mIpAddress; 28 | } 29 | 30 | 31 | public FileReqMeta GenerateMetadataRequest() 32 | { 33 | //collect details from all fileTransRequests 34 | List fileDetails = new List(); 35 | foreach(FileTransReq fileTransReq in FileTransReqs) 36 | { 37 | fileDetails.Add(fileTransReq.FileDetails); 38 | } 39 | FileReqMeta fileSendMetadata = new FileReqMeta(fileDetails, bufferSize, targetIpAddress); 40 | return fileSendMetadata; 41 | } 42 | 43 | public bool FileHasMoreParts(FileTransReq fileTrans) 44 | { 45 | if(fileTrans.curFilePartNum < fileTrans.TotalPartNum) 46 | { 47 | return true; 48 | } 49 | else 50 | { 51 | return false; 52 | } 53 | } 54 | 55 | public async Task GetNextFilePart(FileTransReq mCurFileTrans) 56 | { 57 | //set buffer lengths 58 | int bufferLen = (int)Math.Min(mCurFileTrans.FileDetails.FileSize - mCurFileTrans.BytesProcessed, this.bufferSize); 59 | if(bufferLen <= 0) 60 | { 61 | //nothing more to be sent 62 | return null; 63 | } 64 | FileMeta fileMetadata = mCurFileTrans.FileDetails; 65 | byte[] fileData = await mCurFileTrans.ReadBytes(bufferLen); 66 | 67 | 68 | //populate File part object 69 | FilePartObj filePart = new FilePartObj(fileMetadata, fileData, mCurFileTrans.curFilePartNum, mCurFileTrans.TotalPartNum); 70 | 71 | return filePart; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/FileTransReq.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.FileLayer.SendableObjects; 2 | using PCLStorage; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace P2PNET.FileLayer 11 | { 12 | public class FileTransReq 13 | { 14 | //file details 15 | public FileMeta FileDetails { get; } 16 | 17 | public int curFilePartNum 18 | { 19 | get 20 | { 21 | return (int)Math.Ceiling((float)BytesProcessed / bufferSize); 22 | } 23 | } 24 | public int TotalPartNum 25 | { 26 | get 27 | { 28 | return (int)Math.Ceiling((float)FileDetails.FileSize / bufferSize); 29 | } 30 | } 31 | 32 | //transmittion details 33 | public long BytesProcessed 34 | { 35 | get 36 | { 37 | return bytesProccessed; 38 | } 39 | } 40 | private long bytesProccessed; 41 | 42 | //buffer size is only for file parts calculations 43 | private int bufferSize; 44 | 45 | private Stream fileDataStream; 46 | 47 | //constructor 48 | public FileTransReq(IFile mFileDetails, Stream mFileStream, int mBufferSize) 49 | { 50 | this.FileDetails = new FileMeta(mFileDetails.Name, mFileDetails.Path, mFileStream.Length); 51 | this.bufferSize = mBufferSize; 52 | this.bytesProccessed = 0; 53 | this.fileDataStream = mFileStream; 54 | } 55 | 56 | //constructor 57 | public FileTransReq(FileMeta fileDetails, Stream mFileStream, int mBufferSize) 58 | { 59 | this.FileDetails = new FileMeta(fileDetails.FileName, fileDetails.FilePath, fileDetails.FileSize); 60 | this.bufferSize = mBufferSize; 61 | this.bytesProccessed = 0; 62 | this.fileDataStream = mFileStream; 63 | } 64 | 65 | //deconstructor 66 | 67 | public async Task ReadBytes(int numOfBytes) 68 | { 69 | byte[] fileData = new byte[numOfBytes]; 70 | 71 | await this.fileDataStream.ReadAsync(fileData, 0, numOfBytes); 72 | 73 | this.bytesProccessed += numOfBytes; 74 | 75 | return fileData; 76 | } 77 | 78 | public async Task WriteBytes(byte[] data) 79 | { 80 | await this.fileDataStream.WriteAsync(data, 0, data.Length); 81 | this.bytesProccessed += data.Length; 82 | } 83 | 84 | public async Task CloseFileStream() 85 | { 86 | await this.fileDataStream.FlushAsync(); 87 | this.fileDataStream.Dispose(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/SendableObjects/FileAck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.SendableObjects 8 | { 9 | public class FileAck 10 | { 11 | //set true to let sender know to keep sending the 12 | //file parts 13 | public bool AcceptedFile { get; set; } 14 | public string FileName { get; set; } 15 | public string FilePath { get; set; } 16 | 17 | public FileAck(FilePartObj filePart, bool acceptFutureParts = true) 18 | { 19 | this.AcceptedFile = acceptFutureParts; 20 | this.FileName = filePart.FileMetadata.FileName; 21 | this.FilePath = filePart.FileMetadata.FilePath; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/SendableObjects/FileMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.SendableObjects 8 | { 9 | public class FileMeta 10 | { 11 | public string FileName { get; set; } 12 | public string FilePath { get; set; } 13 | public long FileSize { get; set; } 14 | 15 | //constructor 16 | public FileMeta(string mFileName, string mFilePath, long mFileSize) 17 | { 18 | this.FileName = mFileName; 19 | this.FilePath = mFilePath; 20 | this.FileSize = mFileSize; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/SendableObjects/FilePartObj.cs: -------------------------------------------------------------------------------- 1 | using PCLStorage; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Runtime.Serialization; 8 | 9 | namespace P2PNET.FileLayer.SendableObjects 10 | { 11 | //file objects are sent between peers 12 | //for that reason they must be seralizable 13 | //contains enough information so that both sender and 14 | //receiver's are stateless 15 | public class FilePartObj 16 | { 17 | //identification 18 | public FileMeta FileMetadata { get; set; } 19 | 20 | //data 21 | public byte[] FileData { get; set; } 22 | 23 | 24 | public int FilePartNum { get; set; } 25 | public int TotalPartNum { get; set; } 26 | 27 | 28 | public FilePartObj(FileMeta mMetadata, byte[] mFileData, int mFilePartNum, int TotalPartNum) 29 | { 30 | this.FileMetadata = mMetadata; 31 | this.FileData = mFileData; 32 | this.FilePartNum = mFilePartNum; 33 | this.TotalPartNum = TotalPartNum; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/SendableObjects/FileReqMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.SendableObjects 8 | { 9 | public class FileReqMeta 10 | { 11 | //data the receiver can use to decide whether or not to reject the request 12 | public List Files { get; set; } 13 | public int BufferSize { get; set; } 14 | 15 | //identification data 16 | public string SenderIpAddress { get; set; } 17 | 18 | public FileReqMeta(List mFiles, int mBufferSize, string mSenderIpAddress) 19 | { 20 | this.Files = mFiles; 21 | this.BufferSize = mBufferSize; 22 | this.SenderIpAddress = mSenderIpAddress; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /P2PNET/FileLayer/SendableObjects/ReqAck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.FileLayer.SendableObjects 8 | { 9 | class ReqAck 10 | { 11 | public bool AcceptedFile { get; set; } 12 | 13 | //constructor 14 | public ReqAck(bool mAcceptedFile) 15 | { 16 | this.AcceptedFile = mAcceptedFile; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /P2PNET/ILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET 8 | { 9 | public interface ILogger 10 | { 11 | void WriteLine(string msg); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /P2PNET/ObjectLayer/BObject.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using P2PNET.ObjectLayer; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace P2PNET.ObjectLayer 10 | { 11 | public class BObject 12 | { 13 | private byte[] msgBin; 14 | private Serializer serializer; 15 | 16 | //constructor 17 | public BObject(byte[] msg, Serializer mSerializer) 18 | { 19 | this.msgBin = msg; 20 | this.serializer = mSerializer; 21 | } 22 | 23 | //overwrite the GetType method 24 | public new string GetType() 25 | { 26 | string jsonMsg = Encoding.Unicode.GetString(msgBin, 0, msgBin.Length); 27 | JObject jObject = JObject.Parse(jsonMsg); 28 | JToken jToken = jObject["Metadata"]; 29 | JToken jObjeType = jToken.SelectToken("ObjectType"); 30 | return jObjeType.Value(); 31 | } 32 | 33 | public Metadata GetMetadata() 34 | { 35 | ObjPackage genericPackage = serializer.DeserializeObject>(msgBin); 36 | return genericPackage.Metadata; 37 | } 38 | 39 | public T GetObject() 40 | { 41 | try 42 | { 43 | ObjPackage objPackage = serializer.DeserializeObject>(msgBin); 44 | return objPackage.Obj; 45 | } 46 | catch(Exception e) 47 | { 48 | throw e; 49 | } 50 | } 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /P2PNET/ObjectLayer/EventArgs/ObjReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.ObjectLayer; 2 | using P2PNET.TransportLayer; 3 | 4 | namespace P2PNET.ObjectLayer.EventArgs 5 | { 6 | public class ObjReceivedEventArgs : System.EventArgs 7 | { 8 | public BObject Obj { get; } 9 | public Metadata Meta { get; } 10 | 11 | //constructor 12 | public ObjReceivedEventArgs(BObject mObj, Metadata mMetadata) 13 | { 14 | this.Obj = mObj; 15 | this.Meta = mMetadata; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /P2PNET/ObjectLayer/Metadata.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.TransportLayer; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.Serialization; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace P2PNET.ObjectLayer 10 | { 11 | public class Metadata 12 | { 13 | //the type of the object 14 | public string ObjectType { get; set; } 15 | 16 | public string SourceIp { get; set; } 17 | 18 | //UDP or TCP 19 | public TransportType? BindType { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /P2PNET/ObjectLayer/ObjPackage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.ObjectLayer 8 | { 9 | public class ObjPackage 10 | { 11 | public T Obj { get; set; } 12 | public Metadata Metadata { get; set; } 13 | 14 | public ObjPackage() 15 | { 16 | } 17 | 18 | //constructor 19 | public ObjPackage(T mObject, Metadata metadata) 20 | { 21 | this.Obj = mObject; 22 | this.Metadata = metadata; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /P2PNET/ObjectLayer/Serializer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Bson; 3 | using P2PNET.FileLayer.EventArgs; 4 | using System; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace P2PNET.ObjectLayer 9 | { 10 | public class Serializer 11 | { 12 | public byte[] SerializeObject(T obj) 13 | { 14 | string msgString = SerializeObjectJSON(obj); 15 | 16 | byte[] msgBin = Encoding.Unicode.GetBytes(msgString); 17 | 18 | //byte[] msgBin = SerializeObjectBSON(keyMsg); 19 | return msgBin; 20 | } 21 | 22 | public T DeserializeObject(byte[] msg) 23 | { 24 | string msgString = Encoding.Unicode.GetString(msg, 0, msg.Length); 25 | T obj = DeserializeObjectJSON(msgString); 26 | //T obj = DeserializeObjectBSON(msg); 27 | return obj; 28 | } 29 | 30 | private string PrintBinary(byte[] byteArray) 31 | { 32 | var sb = new StringBuilder("new byte[] { "); 33 | for (var i = 0; i < byteArray.Length; i++) 34 | { 35 | var b = byteArray[i]; 36 | sb.Append(b); 37 | if (i < byteArray.Length - 1) 38 | { 39 | sb.Append(", "); 40 | } 41 | } 42 | sb.Append(" }"); 43 | return sb.ToString(); 44 | } 45 | 46 | //seralizes the object to Binary JSON 47 | //this has better output size when sending binary files (which typically 48 | //make up the majority of file sizes) 49 | private byte[] SerializeObjectBSON(T keyMsg) 50 | { 51 | //generate metadata 52 | //ObjectMetadata x; 53 | 54 | MemoryStream ms = new MemoryStream(); 55 | BsonWriter writer = new BsonWriter(ms); 56 | JsonSerializer serializer = new JsonSerializer(); 57 | serializer.Serialize(writer, keyMsg); 58 | return ms.ToArray(); 59 | } 60 | 61 | private T DeserializeObjectBSON(byte[] msg) 62 | { 63 | MemoryStream ms = new MemoryStream(msg); 64 | using (BsonReader reader = new BsonReader(ms)) 65 | { 66 | JsonSerializer serializer = new JsonSerializer(); 67 | T e = serializer.Deserialize(reader); 68 | return e; 69 | } 70 | } 71 | 72 | private string SerializeObjectJSON(T keyMsg) 73 | { 74 | return JsonConvert.SerializeObject(keyMsg, Formatting.Indented); 75 | } 76 | 77 | private T DeserializeObjectJSON(string msg) 78 | { 79 | return JsonConvert.DeserializeObject(msg); 80 | } 81 | 82 | public int ReadInt32(byte[] bytes) 83 | { 84 | byte[] bin = new byte[sizeof(int)]; 85 | Array.Copy(bytes, bin, sizeof(int)); 86 | if(BitConverter.IsLittleEndian) 87 | { 88 | Array.Reverse(bin); 89 | } 90 | int value = BitConverter.ToInt32(bin, 0); 91 | return value; 92 | } 93 | 94 | public byte[] WriteInt32(int value) 95 | { 96 | byte[] binary = BitConverter.GetBytes(value); 97 | if(BitConverter.IsLittleEndian) 98 | { 99 | Array.Reverse(binary); 100 | } 101 | return binary; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /P2PNET/P2PNET.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SquidInc.P2PNET 5 | $version$ 6 | $title$ 7 | Clinton Page 8 | en-US 9 | Clinton Page 10 | https://github.com/BlueSquid1/P2PNET 11 | https://github.com/BlueSquid1/P2PNET/blob/master/LICENSE 12 | false 13 | P2PNET is a low level portable peer to peer library written in C# with an emphasises on being simple to use 14 | Further stability updates 15 | Copyright 2017 16 | P2P NET peer2peer peer network networking symetric .net P2PNET sockets tcp udp xamarin windows phone wp8 winrt uwp android xamarin.forms asp.net ios 17 | 18 | -------------------------------------------------------------------------------- /P2PNET/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("P2PNET")] 10 | [assembly: AssemblyDescription("Peer-To-Peer network library")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Clinton Page")] 13 | [assembly: AssemblyProduct("P2PNET")] 14 | [assembly: AssemblyCopyright("Copyright © 2016")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: NeutralResourcesLanguage("en")] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.5.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /P2PNET/TransportLayer/AbstractStreamUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace P2PNET.TransportLayer 9 | { 10 | class AbstractStreamUtil 11 | { 12 | public Stream ActiveStream { get; set; } 13 | 14 | //constructor 15 | public AbstractStreamUtil(Stream inputStream) 16 | { 17 | this.ActiveStream = inputStream; 18 | } 19 | 20 | protected byte[] IntToBinary(int value) 21 | { 22 | byte[] valueBin = BitConverter.GetBytes(value); 23 | if (BitConverter.IsLittleEndian) 24 | { 25 | Array.Reverse(valueBin); 26 | } 27 | return valueBin; 28 | } 29 | 30 | protected int BinaryToInt(byte[] binArray) 31 | { 32 | if (BitConverter.IsLittleEndian) 33 | { 34 | Array.Reverse(binArray); 35 | } 36 | return BitConverter.ToInt32(binArray, 0); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/BufferedUDPStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace P2PNET.TransportLayer 5 | { 6 | internal class BufferedUDPStream : Stream 7 | { 8 | public override bool CanRead 9 | { 10 | get 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | } 15 | 16 | public override bool CanSeek 17 | { 18 | get 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | } 23 | 24 | public override bool CanWrite 25 | { 26 | get 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } 31 | 32 | public override long Length 33 | { 34 | get 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | } 39 | 40 | public override long Position 41 | { 42 | get 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | set 48 | { 49 | throw new NotImplementedException(); 50 | } 51 | } 52 | 53 | public override void Flush() 54 | { 55 | throw new NotImplementedException(); 56 | } 57 | 58 | public override int Read(byte[] buffer, int offset, int count) 59 | { 60 | throw new NotImplementedException(); 61 | } 62 | 63 | public override long Seek(long offset, SeekOrigin origin) 64 | { 65 | throw new NotImplementedException(); 66 | } 67 | 68 | public override void SetLength(long value) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | 73 | public override void Write(byte[] buffer, int offset, int count) 74 | { 75 | throw new NotImplementedException(); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /P2PNET/TransportLayer/EventArgs/MsgReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace P2PNET.TransportLayer.EventArgs 2 | { 3 | public class MsgReceivedEventArgs : System.EventArgs 4 | { 5 | public byte[] Message { get; } 6 | public TransportType BindingType { get; } 7 | public string RemoteIp { get; } 8 | 9 | public MsgReceivedEventArgs(string remoteIp, byte[] msg, TransportType bindType) 10 | { 11 | this.RemoteIp = remoteIp; 12 | this.Message = msg; 13 | this.BindingType = bindType; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/EventArgs/PeerChangeEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | 4 | namespace P2PNET.TransportLayer.EventArgs 5 | { 6 | public class PeerChangeEventArgs : System.EventArgs 7 | { 8 | public List Peers { get; } 9 | 10 | //constructor 11 | public PeerChangeEventArgs( List peers ) 12 | { 13 | this.Peers = peers; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/EventArgs/PeerEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | 4 | namespace P2PNET.TransportLayer.EventArgs 5 | { 6 | public class PeerEventArgs : System.EventArgs 7 | { 8 | public Peer Peer { get; } 9 | 10 | //constructor 11 | public PeerEventArgs( Peer peer ) 12 | { 13 | this.Peer = peer; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/Peer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.IO; 4 | using Sockets.Plugin.Abstractions; 5 | using P2PNET.TransportLayer.EventArgs; 6 | using System.Text; 7 | using System.Linq; 8 | 9 | namespace P2PNET.TransportLayer 10 | { 11 | public class Peer 12 | { 13 | public event EventHandler MsgReceived; 14 | public event EventHandler peerStatusChange; 15 | public ILogger logger; 16 | 17 | public string IpAddress 18 | { 19 | get 20 | { 21 | return socketClient.RemoteAddress; 22 | } 23 | } 24 | 25 | public bool IsPeerActive { get; set; } 26 | 27 | public Stream WriteStream 28 | { 29 | get 30 | { 31 | return writeUtil.ActiveStream; 32 | } 33 | } 34 | 35 | public Stream ReadStream 36 | { 37 | get 38 | { 39 | return readUtil.ActiveStream; 40 | } 41 | } 42 | 43 | private WriteStreamUtil writeUtil; 44 | private ReadStreamUtil readUtil; 45 | 46 | private ITcpSocketClient socketClient; 47 | 48 | //constructor 49 | public Peer(ITcpSocketClient mSocketClient, ILogger mLogger) 50 | { 51 | this.IsPeerActive = true; 52 | this.socketClient = mSocketClient; 53 | this.logger = mLogger; 54 | writeUtil = new WriteStreamUtil(this.socketClient.WriteStream); 55 | readUtil = new ReadStreamUtil(this.socketClient.ReadStream); 56 | 57 | StartListening(); 58 | } 59 | 60 | public async Task SendMsgTCPAsync(byte[] msg) 61 | { 62 | if(this.IsPeerActive == false) 63 | { 64 | //peer has disconnected 65 | return false; 66 | } 67 | 68 | await writeUtil.WriteBytesAsync(msg); 69 | return true; 70 | } 71 | 72 | private async void StartListening() 73 | { 74 | //set timeout for reading 75 | while (this.IsPeerActive) 76 | { 77 | byte[] messageBin = null; 78 | try 79 | { 80 | messageBin = await readUtil.ReadBytesAsync(); 81 | } 82 | catch 83 | { 84 | //lost connection with peer 85 | this.IsPeerActive = false; 86 | peerStatusChange?.Invoke(this, new PeerEventArgs(this)); 87 | } 88 | if(IsPeerActive == true) 89 | { 90 | MsgReceived?.Invoke(this, new MsgReceivedEventArgs(socketClient.RemoteAddress, messageBin, TransportType.TCP)); 91 | } 92 | } 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /P2PNET/TransportLayer/ReadStreamUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace P2PNET.TransportLayer 9 | { 10 | class ReadStreamUtil : AbstractStreamUtil 11 | { 12 | //constructor 13 | public ReadStreamUtil(Stream mReadStream) : base(mReadStream) 14 | { 15 | 16 | } 17 | 18 | public async Task ReadBytesAsync() 19 | { 20 | //read the first 4 bytes = sizeof(int) 21 | const int intSize = sizeof(int); 22 | Byte[] lengthBin = await ReadBytesAsync(intSize); 23 | int msgSize = BinaryToInt(lengthBin); 24 | 25 | //read message 26 | byte[] messageBin = await ReadBytesAsync(msgSize); 27 | return messageBin; 28 | } 29 | 30 | private async Task ReadBytesAsync(int bytesToRead) 31 | { 32 | Byte[] msgBin = new Byte[bytesToRead]; 33 | int totalBytesRd = 0; 34 | while (totalBytesRd < bytesToRead) 35 | { 36 | //ReadAsync() can return less then intSize therefore keep on looping until intSize is reached 37 | byte[] tempMsgBin = new Byte[bytesToRead]; 38 | int bytesRead = await base.ActiveStream.ReadAsync(tempMsgBin, 0, bytesToRead - totalBytesRd); 39 | Array.Copy(tempMsgBin, 0, msgBin, totalBytesRd, bytesRead); 40 | totalBytesRd += bytesRead; 41 | } 42 | return msgBin; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/TransportType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.TransportLayer 8 | { 9 | public enum TransportType 10 | { 11 | TCP, 12 | UDP 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /P2PNET/TransportLayer/WriteStreamUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace P2PNET.TransportLayer 11 | { 12 | class WriteStreamUtil : AbstractStreamUtil 13 | { 14 | private SemaphoreSlim queueSem = new SemaphoreSlim(1); 15 | private SemaphoreSlim messageSem = new SemaphoreSlim(1); 16 | 17 | private Queue msgBuffer; 18 | 19 | //constructor 20 | public WriteStreamUtil(Stream mWriteStream ) : base(mWriteStream) 21 | { 22 | msgBuffer = new Queue(); 23 | } 24 | 25 | public async Task WriteBytesAsync(byte[] msg) 26 | { 27 | //add message to buffer 28 | await queueSem.WaitAsync(); 29 | try 30 | { 31 | msgBuffer.Enqueue(msg); 32 | } 33 | finally 34 | { 35 | queueSem.Release(); 36 | } 37 | 38 | //make sure only one message is sent at a time 39 | await messageSem.WaitAsync(); 40 | try 41 | { 42 | byte[] nextMsg; 43 | await queueSem.WaitAsync(); 44 | try 45 | { 46 | //read next message from buffer 47 | if (msgBuffer.Count <= 0) 48 | { 49 | throw new LowLevelTransitionError("Expected more messages in the write buffer."); 50 | } 51 | nextMsg = msgBuffer.Dequeue(); 52 | } 53 | finally 54 | { 55 | queueSem.Release(); 56 | } 57 | 58 | //send number indicating message size 59 | int lenMsg = (int)nextMsg.Length; 60 | byte[] lenBin = IntToBinary(lenMsg); 61 | await base.ActiveStream.WriteAsync(lenBin, 0, lenBin.Length); 62 | 63 | //send the msg 64 | if (lenMsg > 0) 65 | { 66 | await base.ActiveStream.WriteAsync(nextMsg, 0, lenMsg); 67 | } 68 | await base.ActiveStream.FlushAsync(); 69 | } 70 | finally 71 | { 72 | messageSem.Release(); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /P2PNET/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # P2PNET 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/5y5reox45a5fjm5u?svg=true)](https://ci.appveyor.com/project/CrazySquid1/p2pnet) 4 | 5 | 6 | P2PNET is a low level portable peer to peer library written in C# with an emphasises on being simple to use. With this library you can send and receive messages, files and objects between peers on a local network. P2PNET is fast. Messages are serialized with JSON.NET and then send directly using a transport layer protocol. This make P2PNET ideal for soft real time systems (i.e. video games). 7 | 8 | Establishing a low level peer-to-peer network connection can be hard as you have to deal with the asymmetric nature of establishing a TCP connection and the add complexities of mutli-threaded programs. This library is designed to simplify this. In fact you don't have to worry about threads or establishing a connection at all. You can just use one of the supplied send methods to start sending messages. P2PNET will handles establishing a TCP connection for you. 9 | 10 | you can send all kinds of messages. For low level applications use: P2PNET.TransportLayer.TransportManager to send binary arrays. Alternatively you can use P2PNET.ObjectLayer.ObjectManager to send objects between peers. And in future I plan to implement the ability to send files. 11 | 12 | Supported protocols: 13 | * UDP and TCP 14 | 15 | 16 | ## Supported Platforms: 17 | * Mono / .Net Framework 4.5 18 | * ASP.NET Core 1.0 19 | * Windows 8 20 | * Windows Phone 8.1 21 | * Windows Phone Silverlight 8 22 | * Xamarin.Android 23 | * Xamarin.iOS 24 | * Xamarin.iOS (Classic) 25 | * UWP 26 | 27 | ## How do I add this library to my project? 28 | The latest release can be found on [NuGet](https://www.nuget.org/packages/SquidInc.P2PNET/). Use a [Nuget Package Manager](http://www.c-sharpcorner.com/UploadFile/8a67c0/use-nuget-package-manager-in-visual-studio-2015/) to include it into your C# project. 29 | 30 | ## How To Use 31 | ```c# 32 | int portNum = 8080; 33 | TransportManager transMgr = new TransportManager(portNum); 34 | transManager.MsgReceived += (object obj, MsgReceivedEventArgs e) => 35 | { 36 | byte[] message = e.Message; 37 | //insert code here 38 | }; 39 | 40 | //tell P2PNET to start listerning 41 | await transMgr.StartAsync(); 42 | 43 | 44 | //when you want to send a message 45 | string ipAddress = "255.255.255.255"; 46 | byte[] message = Encoding.ASCII.GetBytes("Hello world"); 47 | transMgr.SendAsyncTCP(ipAddress, message); 48 | ``` 49 | 50 | Refer to wiki for more details. -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Cat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectSender 8 | { 9 | class Cat : Pet 10 | { 11 | public Cat(string petName) : base(petName) 12 | { 13 | this.Type = AnimalType.Cat; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Dog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectSender 8 | { 9 | class Dog : Pet 10 | { 11 | 12 | public Dog(string petName) : base(petName) 13 | { 14 | this.Type = AnimalType.Dog; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Fish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectSender 8 | { 9 | class Fish : Pet 10 | { 11 | public bool FreshWater { get; set; } 12 | public Fish(string petName) : base(petName) 13 | { 14 | this.Type = AnimalType.Fish; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/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.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using P2PNET.ObjectLayer; 11 | 12 | namespace ObjectSender 13 | { 14 | public partial class Form1 : Form 15 | { 16 | private ObjectManager ObjMgr; 17 | private int portNum = 8080; 18 | 19 | public Form1() 20 | { 21 | ObjMgr = new ObjectManager(portNum, true); 22 | InitializeComponent(); 23 | } 24 | 25 | private async void Form1_Load(object sender, EventArgs e) 26 | { 27 | ObjMgr.ObjReceived += ObjMgr_ObjReceived; 28 | await ObjMgr.StartAsync(); 29 | } 30 | 31 | private void ObjMgr_ObjReceived(object sender, P2PNET.ObjectLayer.EventArgs.ObjReceivedEventArgs e) 32 | { 33 | Metadata metadata = e.Meta; 34 | PrintMetadata(metadata); 35 | switch (metadata.ObjectType) 36 | { 37 | case "Dog": 38 | Dog receivedDog = e.Obj.GetObject(); 39 | PrintDog(receivedDog); 40 | break; 41 | case "Cat": 42 | Cat receivedCat = e.Obj.GetObject(); 43 | PrintCat(receivedCat); 44 | break; 45 | case "Fish": 46 | Fish receivedFish = e.Obj.GetObject(); 47 | PrintFish(receivedFish); 48 | break; 49 | case "Person": 50 | Person receivedPerson = e.Obj.GetObject(); 51 | PrintPerson(receivedPerson); 52 | break; 53 | default: 54 | Console.WriteLine("unknown object type"); 55 | break; 56 | } 57 | } 58 | 59 | private void PrintMetadata(Metadata meta) 60 | { 61 | Console.WriteLine("source = " + meta.SourceIp + ", " + meta.BindType); 62 | } 63 | 64 | private void PrintDog(Dog dog) 65 | { 66 | Console.WriteLine("dog name = "+ dog.Name); 67 | } 68 | 69 | private void PrintPet(Pet pet) 70 | { 71 | Console.WriteLine("Pet type = " + pet.Type + ", name = " + pet.Name); 72 | } 73 | 74 | private void PrintCat(Cat cat) 75 | { 76 | Console.WriteLine("cat name = " + cat.Name); 77 | } 78 | 79 | private void PrintFish(Fish fish) 80 | { 81 | Console.WriteLine("fish name = " + fish.Name + ", is fresh water = " + fish.FreshWater); 82 | } 83 | 84 | private void PrintPerson(Person person) 85 | { 86 | Console.WriteLine("person name = " + person.FirstName + " " + person.LastName + ", Age = " + person.Age); 87 | foreach(Pet pet in person.OwnedPets) 88 | { 89 | PrintPet(pet); 90 | } 91 | } 92 | 93 | 94 | private async void btnSendDog_Click(object sender, EventArgs e) 95 | { 96 | Dog petDog = new Dog(txtDogName.Text); 97 | string ipAddress = GetIpAddress(); 98 | await ObjMgr.SendAsyncTCP(ipAddress, petDog); 99 | } 100 | 101 | private async void btnSendCat_Click(object sender, EventArgs e) 102 | { 103 | Cat petCat = new Cat(txtCatName.Text); 104 | string ipAddress = GetIpAddress(); 105 | await ObjMgr.SendAsyncTCP(ipAddress, petCat); 106 | } 107 | 108 | private async void btnSendFish_Click(object sender, EventArgs e) 109 | { 110 | Fish petFish = new Fish(txtFishName.Text); 111 | string ipAddress = GetIpAddress(); 112 | await ObjMgr.SendAsyncTCP(ipAddress, petFish); 113 | } 114 | 115 | private async void btnSendPerson_Click(object sender, EventArgs e) 116 | { 117 | Person person = new Person(txtFirstName.Text, txtLastName.Text, 20); 118 | 119 | if (chkIncludeDog.Checked ) 120 | { 121 | person.AddPet(new Dog(txtDogName.Text)); 122 | } 123 | 124 | if (chkIncludeCat.Checked) 125 | { 126 | person.AddPet(new Cat(txtCatName.Text)); 127 | } 128 | 129 | if (chkIncludeFish.Checked) 130 | { 131 | person.AddPet(new Fish(txtFishName.Text)); 132 | } 133 | 134 | string ipAddress = GetIpAddress(); 135 | await ObjMgr.SendAsyncTCP(ipAddress, person); 136 | } 137 | 138 | private string GetIpAddress() 139 | { 140 | string tempIpAddress = txtIpAddress.Text; 141 | if(tempIpAddress == "") 142 | { 143 | Console.WriteLine("warning. No ip address entered."); 144 | } 145 | return tempIpAddress; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/ObjectSender.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DEC94D14-4588-4558-93D2-CA04CFF85799} 8 | Exe 9 | Properties 10 | ObjectSender 11 | ObjectSender 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 41 | True 42 | 43 | 44 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 45 | True 46 | 47 | 48 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 49 | True 50 | 51 | 52 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 53 | True 54 | 55 | 56 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 57 | True 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Form 77 | 78 | 79 | Form1.cs 80 | 81 | 82 | 83 | 84 | 85 | 86 | Form1.cs 87 | 88 | 89 | ResXFileCodeGenerator 90 | Resources.Designer.cs 91 | Designer 92 | 93 | 94 | True 95 | Resources.resx 96 | 97 | 98 | 99 | SettingsSingleFileGenerator 100 | Settings.Designer.cs 101 | 102 | 103 | True 104 | Settings.settings 105 | True 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | {196653e2-638f-4590-82e6-79387f5b2fb9} 114 | P2PNET 115 | 116 | 117 | 118 | 125 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectSender 8 | { 9 | public class Person : Object 10 | { 11 | public string FirstName { get; set; } 12 | public string LastName { get; set; } 13 | 14 | public int Age { get; set; } 15 | 16 | public List OwnedPets { get; set; } 17 | 18 | public Person(string firstName, string lastName, int age) 19 | { 20 | this.FirstName = firstName; 21 | this.LastName = lastName; 22 | this.Age = age; 23 | 24 | OwnedPets = new List(); 25 | } 26 | 27 | public void AddPet(Pet newPet) 28 | { 29 | OwnedPets.Add(newPet); 30 | } 31 | 32 | public bool Equals(Person secPerson) 33 | { 34 | if(secPerson == null) 35 | { 36 | Console.WriteLine("person is null"); 37 | return false; 38 | } 39 | if(secPerson.OwnedPets.Count != this.OwnedPets.Count) 40 | { 41 | Console.WriteLine("num of pets different"); 42 | return false; 43 | } 44 | 45 | 46 | for(int i = 0; i < OwnedPets.Count; i++) 47 | { 48 | if(!this.OwnedPets[i].Equals(secPerson.OwnedPets[i])) 49 | { 50 | Console.WriteLine("pet have different values"); 51 | return false; 52 | } 53 | } 54 | 55 | if(secPerson.Age != this.Age || secPerson.FirstName != this.FirstName || secPerson.LastName != this.LastName) 56 | { 57 | Console.WriteLine("people have different values"); 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Pet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ObjectSender 8 | { 9 | public enum AnimalType 10 | { 11 | Dog = 0, 12 | Cat = 1, 13 | Fish = 2 14 | } 15 | public class Pet 16 | { 17 | public AnimalType Type { get; set; } 18 | public string Name { get; set; } 19 | 20 | public Pet(string petName) 21 | { 22 | this.Name = petName; 23 | } 24 | 25 | public bool Equals(Pet pet) 26 | { 27 | if(pet.Name == this.Name && pet.Type == this.Type) 28 | { 29 | return true; 30 | } 31 | return false; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ObjectSender 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/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("ObjectSender")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ObjectSender")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("dec94d14-4588-4558-93d2-ca04cff85799")] 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/ObjectSamples/ObjectSender/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 ObjectSender.Properties 12 | { 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 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ObjectSender.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 ObjectSender.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Samples/ObjectSamples/ObjectSender/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/AutoDiscovery.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5} 8 | Exe 9 | Properties 10 | AutoDiscovery 11 | AutoDiscovery 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 41 | True 42 | 43 | 44 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 45 | True 46 | 47 | 48 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 49 | True 50 | 51 | 52 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 53 | True 54 | 55 | 56 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 57 | True 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Form 74 | 75 | 76 | Form1.cs 77 | 78 | 79 | 80 | 81 | 82 | Form1.cs 83 | 84 | 85 | ResXFileCodeGenerator 86 | Resources.Designer.cs 87 | Designer 88 | 89 | 90 | True 91 | Resources.resx 92 | 93 | 94 | 95 | SettingsSingleFileGenerator 96 | Settings.Designer.cs 97 | 98 | 99 | True 100 | Settings.settings 101 | True 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | {196653e2-638f-4590-82e6-79387f5b2fb9} 110 | P2PNET 111 | 112 | 113 | 114 | 121 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace AutoDiscovery 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.peerListView = new System.Windows.Forms.ListView(); 32 | this.ipAddress = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 33 | this.label1 = new System.Windows.Forms.Label(); 34 | this.SuspendLayout(); 35 | // 36 | // peerListView 37 | // 38 | this.peerListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 39 | this.ipAddress}); 40 | this.peerListView.FullRowSelect = true; 41 | this.peerListView.GridLines = true; 42 | this.peerListView.Location = new System.Drawing.Point(12, 76); 43 | this.peerListView.Name = "peerListView"; 44 | this.peerListView.Size = new System.Drawing.Size(260, 127); 45 | this.peerListView.TabIndex = 0; 46 | this.peerListView.UseCompatibleStateImageBehavior = false; 47 | this.peerListView.View = System.Windows.Forms.View.Details; 48 | // 49 | // ipAddress 50 | // 51 | this.ipAddress.Text = "IP Address"; 52 | this.ipAddress.Width = 255; 53 | // 54 | // label1 55 | // 56 | this.label1.AutoSize = true; 57 | this.label1.Location = new System.Drawing.Point(13, 57); 58 | this.label1.Name = "label1"; 59 | this.label1.Size = new System.Drawing.Size(72, 13); 60 | this.label1.TabIndex = 1; 61 | this.label1.Text = "Known peers:"; 62 | // 63 | // Form1 64 | // 65 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 66 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 67 | this.ClientSize = new System.Drawing.Size(284, 261); 68 | this.Controls.Add(this.label1); 69 | this.Controls.Add(this.peerListView); 70 | this.Name = "Form1"; 71 | this.Text = "Peer Discovery"; 72 | this.Load += new System.EventHandler(this.Form1_Load); 73 | this.ResumeLayout(false); 74 | this.PerformLayout(); 75 | 76 | } 77 | 78 | #endregion 79 | 80 | private System.Windows.Forms.ListView peerListView; 81 | private System.Windows.Forms.ColumnHeader ipAddress; 82 | private System.Windows.Forms.Label label1; 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/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.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using P2PNET.TransportLayer; 11 | 12 | namespace AutoDiscovery 13 | { 14 | public partial class Form1 : Form 15 | { 16 | private TransportManager transMgr; 17 | private int portNum = 8080; 18 | private HeartBeatManager hrtBtMgr; 19 | 20 | public Form1() 21 | { 22 | transMgr = new TransportManager(portNum, true); 23 | hrtBtMgr = new HeartBeatManager("heartbeat", transMgr); 24 | 25 | InitializeComponent(); 26 | } 27 | 28 | private async void Form1_Load(object sender, EventArgs e) 29 | { 30 | transMgr.PeerChange += TransMgr_PeerChange; 31 | await transMgr.StartAsync(); 32 | hrtBtMgr.StartBroadcasting(); 33 | } 34 | 35 | private void TransMgr_PeerChange(object sender, P2PNET.TransportLayer.EventArgs.PeerChangeEventArgs e) 36 | { 37 | peerListView.Items.Clear(); 38 | foreach(Peer peer in e.Peers) 39 | { 40 | string[] peerDtl = { 41 | peer.IpAddress 42 | }; 43 | ListViewItem item = new ListViewItem(peerDtl); 44 | peerListView.Items.Add(item); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/HeartBeatManager.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.TransportLayer; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Forms; 8 | 9 | namespace AutoDiscovery 10 | { 11 | class HeartBeatManager 12 | { 13 | private string heartBeatMsg; 14 | private TransportManager transMgr; 15 | private Timer hrtBtTimer; 16 | 17 | //constructor 18 | public HeartBeatManager(string mHeartBeatMsg, TransportManager mTransMgr) 19 | { 20 | this.heartBeatMsg = mHeartBeatMsg; 21 | this.transMgr = mTransMgr; 22 | this.hrtBtTimer = new Timer(); 23 | } 24 | 25 | public void StartBroadcasting() 26 | { 27 | byte[] msgBin = Encoding.ASCII.GetBytes(heartBeatMsg); 28 | 29 | hrtBtTimer.Tick += async (object sender, EventArgs e) => 30 | { 31 | await this.transMgr.SendBroadcastAsyncUDP(msgBin); 32 | Console.WriteLine("sent heartbeat"); 33 | }; 34 | hrtBtTimer.Interval = 1000; 35 | hrtBtTimer.Start(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace AutoDiscovery 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/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("AutoDiscovery")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AutoDiscovery")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("c6fb1278-f3c4-49f3-9838-e449dab2f4b5")] 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/TransportSamples/AutoDiscovery/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 AutoDiscovery.Properties 12 | { 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 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutoDiscovery.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 AutoDiscovery.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Samples/TransportSamples/AutoDiscovery/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/BroadcastProgram.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D415DD7F-5517-46CB-898B-95387248F33D} 8 | WinExe 9 | Properties 10 | BroadcastProgram 11 | BroadcastProgram 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 38 | True 39 | 40 | 41 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 42 | True 43 | 44 | 45 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 46 | True 47 | 48 | 49 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 50 | True 51 | 52 | 53 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 54 | True 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Form 71 | 72 | 73 | Form1.cs 74 | 75 | 76 | 77 | 78 | Form1.cs 79 | 80 | 81 | ResXFileCodeGenerator 82 | Resources.Designer.cs 83 | Designer 84 | 85 | 86 | True 87 | Resources.resx 88 | True 89 | 90 | 91 | 92 | SettingsSingleFileGenerator 93 | Settings.Designer.cs 94 | 95 | 96 | True 97 | Settings.settings 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | {196653e2-638f-4590-82e6-79387f5b2fb9} 107 | P2PNET 108 | 109 | 110 | 111 | 118 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BroadcastProgram 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.btnBroadcast = new System.Windows.Forms.Button(); 32 | this.txtSendMsg = new System.Windows.Forms.TextBox(); 33 | this.txtReceivedMsgs = new System.Windows.Forms.TextBox(); 34 | this.SuspendLayout(); 35 | // 36 | // btnBroadcast 37 | // 38 | this.btnBroadcast.Location = new System.Drawing.Point(177, 219); 39 | this.btnBroadcast.Name = "btnBroadcast"; 40 | this.btnBroadcast.Size = new System.Drawing.Size(95, 23); 41 | this.btnBroadcast.TabIndex = 1; 42 | this.btnBroadcast.Text = "Send Broadcast"; 43 | this.btnBroadcast.UseVisualStyleBackColor = true; 44 | this.btnBroadcast.Click += new System.EventHandler(this.sendBroadcast_Click); 45 | // 46 | // txtSendMsg 47 | // 48 | this.txtSendMsg.Location = new System.Drawing.Point(12, 193); 49 | this.txtSendMsg.Multiline = true; 50 | this.txtSendMsg.Name = "txtSendMsg"; 51 | this.txtSendMsg.Size = new System.Drawing.Size(260, 20); 52 | this.txtSendMsg.TabIndex = 0; 53 | this.txtSendMsg.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtSendMsg_KeyPress); 54 | // 55 | // txtReceivedMsgs 56 | // 57 | this.txtReceivedMsgs.AcceptsReturn = true; 58 | this.txtReceivedMsgs.AcceptsTab = true; 59 | this.txtReceivedMsgs.Location = new System.Drawing.Point(12, 12); 60 | this.txtReceivedMsgs.Multiline = true; 61 | this.txtReceivedMsgs.Name = "txtReceivedMsgs"; 62 | this.txtReceivedMsgs.ReadOnly = true; 63 | this.txtReceivedMsgs.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 64 | this.txtReceivedMsgs.Size = new System.Drawing.Size(260, 175); 65 | this.txtReceivedMsgs.TabIndex = 2; 66 | // 67 | // Form1 68 | // 69 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 70 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 71 | this.ClientSize = new System.Drawing.Size(284, 261); 72 | this.Controls.Add(this.txtReceivedMsgs); 73 | this.Controls.Add(this.txtSendMsg); 74 | this.Controls.Add(this.btnBroadcast); 75 | this.Name = "Form1"; 76 | this.Text = "Broadcaster"; 77 | this.Load += new System.EventHandler(this.Form1_Load); 78 | this.ResumeLayout(false); 79 | this.PerformLayout(); 80 | 81 | } 82 | 83 | #endregion 84 | 85 | private System.Windows.Forms.Button btnBroadcast; 86 | private System.Windows.Forms.TextBox txtSendMsg; 87 | private System.Windows.Forms.TextBox txtReceivedMsgs; 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/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.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using P2PNET.TransportLayer; 11 | using System.Net; 12 | using System.Net.Sockets; 13 | 14 | namespace BroadcastProgram 15 | { 16 | public partial class Form1 : Form 17 | { 18 | private TransportManager transMgr; 19 | private int portNum = 8080; 20 | 21 | public Form1() 22 | { 23 | transMgr = new TransportManager(portNum, true); 24 | InitializeComponent(); 25 | } 26 | 27 | private async void Form1_Load(object sender, EventArgs e) 28 | { 29 | transMgr.MsgReceived += TransMgr_MsgReceived; 30 | await transMgr.StartAsync(); 31 | } 32 | 33 | private void TransMgr_MsgReceived(object sender, P2PNET.TransportLayer.EventArgs.MsgReceivedEventArgs e) 34 | { 35 | string receivedMsg = Encoding.ASCII.GetString(e.Message); 36 | AppendMsg("From ip = " + e.RemoteIp); 37 | AppendMsg(receivedMsg); 38 | AppendMsg(""); 39 | } 40 | 41 | private async void sendBroadcast_Click(object sender, EventArgs e) 42 | { 43 | await SendMsg(txtSendMsg.Text); 44 | } 45 | 46 | private async Task SendMsg(string msgString) 47 | { 48 | byte[] msgBits = Encoding.ASCII.GetBytes(msgString); 49 | await transMgr.SendBroadcastAsyncUDP(msgBits); 50 | 51 | //clear message 52 | txtSendMsg.Text = ""; 53 | 54 | } 55 | 56 | private void AppendMsg(string message) 57 | { 58 | txtReceivedMsgs.AppendText(message + Environment.NewLine); 59 | } 60 | 61 | private async void txtSendMsg_KeyPress(object sender, KeyPressEventArgs e) 62 | { 63 | if(e.KeyChar == '\r') 64 | { 65 | await SendMsg(txtSendMsg.Text); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace BroadcastProgram 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/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("MessageProgram")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MessageProgram")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("d415dd7f-5517-46cb-898b-95387248f33d")] 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/TransportSamples/MessageProgram/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 BroadcastProgram.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("BroadcastProgram.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/TransportSamples/MessageProgram/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 BroadcastProgram.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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/TransportSamples/MessageProgram/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageProgram/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/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.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using P2PNET.TransportLayer; 11 | 12 | namespace MessageSender 13 | { 14 | public partial class Form1 : Form 15 | { 16 | private TransportManager transMgr; 17 | private int portNum = 8080; 18 | 19 | public Form1() 20 | { 21 | transMgr = new TransportManager(portNum, true); 22 | InitializeComponent(); 23 | } 24 | 25 | private async void Form1_Load(object sender, EventArgs e) 26 | { 27 | transMgr.MsgReceived += TransMgr_MsgReceived; 28 | await transMgr.StartAsync(); 29 | } 30 | 31 | private void TransMgr_MsgReceived(object sender, P2PNET.TransportLayer.EventArgs.MsgReceivedEventArgs e) 32 | { 33 | string receivedMsg = Encoding.ASCII.GetString(e.Message); 34 | AppendMsg("From ip = " + e.RemoteIp + " (" + e.BindingType + ")"); 35 | AppendMsg(receivedMsg); 36 | AppendMsg(""); 37 | } 38 | 39 | private async void btnSend_Click(object sender, EventArgs e) 40 | { 41 | await SendMessageImp(); 42 | } 43 | 44 | private void AppendMsg(string message) 45 | { 46 | txtReceivedMessages.AppendText(message + Environment.NewLine); 47 | } 48 | 49 | private async Task SendMsg( string ipAddress, string msgString, TransportType binding) 50 | { 51 | byte[] msgBits = Encoding.ASCII.GetBytes(msgString); 52 | if(binding == TransportType.UDP) 53 | { 54 | await transMgr.SendAsyncUDP(ipAddress, msgBits); 55 | } 56 | else 57 | { 58 | await transMgr.SendAsyncTCP(ipAddress, msgBits); 59 | } 60 | } 61 | 62 | private async void txtSendMessage_KeyPress(object sender, KeyPressEventArgs e) 63 | { 64 | if (e.KeyChar == '\r') 65 | { 66 | await SendMessageImp(); 67 | } 68 | 69 | } 70 | 71 | private async Task SendMessageImp() 72 | { 73 | string ipAddress = txtAddress.Text; 74 | string message = txtSendMessage.Text; 75 | 76 | TransportType bindType; 77 | 78 | if (radTCP.Checked == true) 79 | { 80 | bindType = TransportType.TCP; 81 | } 82 | else 83 | { 84 | bindType = TransportType.UDP; 85 | } 86 | 87 | await SendMsg(ipAddress, message, bindType); 88 | //clear message 89 | txtSendMessage.Text = ""; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/MessageSender.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7} 8 | WinExe 9 | Properties 10 | MessageSender 11 | MessageSender 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 38 | True 39 | 40 | 41 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 42 | True 43 | 44 | 45 | ..\..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 46 | True 47 | 48 | 49 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 50 | True 51 | 52 | 53 | ..\..\..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 54 | True 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Form 71 | 72 | 73 | Form1.cs 74 | 75 | 76 | 77 | 78 | Form1.cs 79 | 80 | 81 | ResXFileCodeGenerator 82 | Resources.Designer.cs 83 | Designer 84 | 85 | 86 | True 87 | Resources.resx 88 | True 89 | 90 | 91 | 92 | SettingsSingleFileGenerator 93 | Settings.Designer.cs 94 | 95 | 96 | True 97 | Settings.settings 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | {196653e2-638f-4590-82e6-79387f5b2fb9} 107 | P2PNET 108 | 109 | 110 | 111 | 118 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace MessageSender 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/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("SendObjects")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SendObjects")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("6464da1f-347c-4f10-ba92-e1e441b7aaa7")] 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/TransportSamples/MessageSender/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 MessageSender.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("MessageSender.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/TransportSamples/MessageSender/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 MessageSender.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.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/TransportSamples/MessageSender/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Samples/TransportSamples/MessageSender/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/WorkSpace/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Cat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Cat : Pet 10 | { 11 | public Cat(string petName) : base(petName) 12 | { 13 | this.Type = AnimalType.Cat; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Dog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Dog : Pet 10 | { 11 | 12 | public Dog(string petName) : base(petName) 13 | { 14 | this.Type = AnimalType.Dog; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Fish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | class Fish : Pet 10 | { 11 | public Fish(string petName) : base(petName) 12 | { 13 | this.Type = AnimalType.Fish; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace WorkSpace 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.SendObj = new System.Windows.Forms.Button(); 32 | this.SendFile = new System.Windows.Forms.Button(); 33 | this.txtFilePath = new System.Windows.Forms.TextBox(); 34 | this.txtIpAddress = new System.Windows.Forms.TextBox(); 35 | this.SendMsg = new System.Windows.Forms.Button(); 36 | this.Close = new System.Windows.Forms.Button(); 37 | this.Stream = new System.Windows.Forms.Button(); 38 | this.SuspendLayout(); 39 | // 40 | // SendObj 41 | // 42 | this.SendObj.Location = new System.Drawing.Point(101, 170); 43 | this.SendObj.Name = "SendObj"; 44 | this.SendObj.Size = new System.Drawing.Size(75, 23); 45 | this.SendObj.TabIndex = 0; 46 | this.SendObj.Text = "SendObj"; 47 | this.SendObj.UseVisualStyleBackColor = true; 48 | this.SendObj.Click += new System.EventHandler(this.SendObj_Click); 49 | // 50 | // SendFile 51 | // 52 | this.SendFile.Location = new System.Drawing.Point(101, 199); 53 | this.SendFile.Name = "SendFile"; 54 | this.SendFile.Size = new System.Drawing.Size(75, 23); 55 | this.SendFile.TabIndex = 1; 56 | this.SendFile.Text = "SendFile"; 57 | this.SendFile.UseVisualStyleBackColor = true; 58 | this.SendFile.Click += new System.EventHandler(this.SendFile_Click); 59 | // 60 | // txtFilePath 61 | // 62 | this.txtFilePath.Location = new System.Drawing.Point(52, 61); 63 | this.txtFilePath.Name = "txtFilePath"; 64 | this.txtFilePath.Size = new System.Drawing.Size(149, 20); 65 | this.txtFilePath.TabIndex = 2; 66 | this.txtFilePath.Text = "06-train-cat-shake-hands.jpg"; 67 | // 68 | // txtIpAddress 69 | // 70 | this.txtIpAddress.Location = new System.Drawing.Point(101, 88); 71 | this.txtIpAddress.Name = "txtIpAddress"; 72 | this.txtIpAddress.Size = new System.Drawing.Size(100, 20); 73 | this.txtIpAddress.TabIndex = 3; 74 | this.txtIpAddress.Text = "192.168.1.110"; 75 | // 76 | // SendMsg 77 | // 78 | this.SendMsg.Location = new System.Drawing.Point(101, 229); 79 | this.SendMsg.Name = "SendMsg"; 80 | this.SendMsg.Size = new System.Drawing.Size(75, 23); 81 | this.SendMsg.TabIndex = 5; 82 | this.SendMsg.Text = "SendMsg"; 83 | this.SendMsg.UseVisualStyleBackColor = true; 84 | this.SendMsg.Click += new System.EventHandler(this.SendMsg_Click); 85 | // 86 | // Close 87 | // 88 | this.Close.Location = new System.Drawing.Point(101, 259); 89 | this.Close.Name = "Close"; 90 | this.Close.Size = new System.Drawing.Size(75, 23); 91 | this.Close.TabIndex = 6; 92 | this.Close.Text = "Close"; 93 | this.Close.UseVisualStyleBackColor = true; 94 | // 95 | // Stream 96 | // 97 | this.Stream.Location = new System.Drawing.Point(197, 187); 98 | this.Stream.Name = "Stream"; 99 | this.Stream.Size = new System.Drawing.Size(75, 23); 100 | this.Stream.TabIndex = 7; 101 | this.Stream.Text = "StreamSend"; 102 | this.Stream.UseVisualStyleBackColor = true; 103 | this.Stream.Click += new System.EventHandler(this.Stream_Click); 104 | // 105 | // Form1 106 | // 107 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 108 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 109 | this.ClientSize = new System.Drawing.Size(284, 302); 110 | this.Controls.Add(this.Stream); 111 | this.Controls.Add(this.Close); 112 | this.Controls.Add(this.SendMsg); 113 | this.Controls.Add(this.txtIpAddress); 114 | this.Controls.Add(this.txtFilePath); 115 | this.Controls.Add(this.SendFile); 116 | this.Controls.Add(this.SendObj); 117 | this.Name = "Form1"; 118 | this.Text = "Form1"; 119 | this.Load += new System.EventHandler(this.Form1_Load); 120 | this.ResumeLayout(false); 121 | this.PerformLayout(); 122 | 123 | } 124 | 125 | #endregion 126 | 127 | private System.Windows.Forms.Button SendObj; 128 | private System.Windows.Forms.Button SendFile; 129 | private System.Windows.Forms.TextBox txtFilePath; 130 | private System.Windows.Forms.TextBox txtIpAddress; 131 | private System.Windows.Forms.Button SendMsg; 132 | private System.Windows.Forms.Button Close; 133 | private System.Windows.Forms.Button Stream; 134 | } 135 | } 136 | 137 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Form1.cs: -------------------------------------------------------------------------------- 1 | using P2PNET.FileLayer; 2 | using P2PNET.ObjectLayer; 3 | using P2PNET.ObjectLayer.EventArgs; 4 | using P2PNET.Test; 5 | using P2PNET.TransportLayer; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Net; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace WorkSpace 13 | { 14 | public partial class Form1 : Form 15 | { 16 | private TransportManager transManager; 17 | 18 | private List peers; 19 | 20 | public Form1() 21 | { 22 | peers = new List(); 23 | transManager = new TransportManager(8080, true); 24 | 25 | InitializeComponent(); 26 | } 27 | 28 | private void TransManager_MsgReceived(object sender, P2PNET.TransportLayer.EventArgs.MsgReceivedEventArgs e) 29 | { 30 | byte[] msg = e.Message; 31 | 32 | for(int i = 0; i < msg.Length; i++) 33 | { 34 | Console.Write(msg[i]); 35 | } 36 | Console.WriteLine(); 37 | } 38 | 39 | private void FileManager_PeerChange(object sender, P2PNET.TransportLayer.EventArgs.PeerChangeEventArgs e) 40 | { 41 | peers = e.Peers; 42 | Console.WriteLine("----peer change----"); 43 | foreach(Peer peer in e.Peers) 44 | { 45 | Console.WriteLine(peer.IpAddress); 46 | } 47 | Console.WriteLine("====peer change====="); 48 | } 49 | 50 | 51 | private async void Form1_Load(object sender, EventArgs e) 52 | { 53 | transManager.MsgReceived += TransManager_MsgReceived; 54 | transManager.PeerChange += FileManager_PeerChange; 55 | await transManager.StartAsync(); 56 | //await objMgr.StartAsync(); 57 | //await fileManager.StartAsync(); 58 | //await transManager.StartAsync(); 59 | } 60 | private async void SendObj_Click(object sender, EventArgs e) 61 | { 62 | Person x = new Person("Harry", "Potter", 25); 63 | //await objMgr.SendBroadcastAsyncUDP(x); 64 | } 65 | 66 | private async void SendFile_Click(object sender, EventArgs e) 67 | { 68 | //string targetIp = "192.168.1.114"; 69 | //string targetIp = "192.168.1.112"; //me 70 | string targetIp = txtIpAddress.Text; 71 | 72 | //string filePath = "test_file.txt"; 73 | //string filePath = "06-train-cat-shake-hands.jpg"; 74 | string filePath = txtFilePath.Text; 75 | List filePaths = new List(); 76 | filePaths.Add("06-train-cat-shake-hands.jpg"); 77 | filePaths.Add("Debug.7z"); 78 | //await fileManager.SendFileAsync(targetIp, filePaths); 79 | } 80 | 81 | private async void SendMsg_Click(object sender, EventArgs e) 82 | { 83 | string targetIp = txtIpAddress.Text; 84 | byte[] msg = new byte[] { 255, 0, 15, 70 }; 85 | 86 | await transManager.SendAsyncTCP(targetIp, msg); 87 | } 88 | 89 | private async void Stream_Click(object sender, EventArgs e) 90 | { 91 | byte[] msg = new byte[] { 0, 25, 10 }; 92 | 93 | //send number indicating message size 94 | int lenMsg = (int)msg.Length; 95 | byte[] lenBin = IntToBinary(lenMsg); 96 | await peers[0].WriteStream.WriteAsync(lenBin, 0, lenBin.Length); 97 | 98 | //send the msg 99 | await peers[0].WriteStream.WriteAsync(msg, 0, lenMsg); 100 | await peers[0].WriteStream.FlushAsync(); 101 | } 102 | 103 | private byte[] IntToBinary(int value) 104 | { 105 | byte[] valueBin = BitConverter.GetBytes(value); 106 | if (BitConverter.IsLittleEndian) 107 | { 108 | Array.Reverse(valueBin); 109 | } 110 | return valueBin; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | 10 | public class FavNum 11 | { 12 | public int number { get; set; } 13 | } 14 | 15 | public class Person 16 | { 17 | public string FirstName { get; set; } 18 | public string LastName { get; set; } 19 | 20 | public int Age { get; set; } 21 | 22 | //public List favNums { get; set; } 23 | public List OwnedPets { get; set; } 24 | 25 | public Person(string firstName, string lastName, int age) 26 | { 27 | //this.favNums = new List(); 28 | this.FirstName = firstName; 29 | this.LastName = lastName; 30 | this.Age = age; 31 | 32 | OwnedPets = new List(); 33 | } 34 | 35 | /* 36 | public void AddNum(FavNum favNum) 37 | { 38 | favNums.Add(favNum); 39 | } 40 | */ 41 | 42 | public void AddPet(Pet newPet) 43 | { 44 | OwnedPets.Add(newPet); 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Pet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace P2PNET.Test 8 | { 9 | public enum AnimalType 10 | { 11 | Dog = 0, 12 | Cat = 1, 13 | Fish = 2 14 | } 15 | public class Pet 16 | { 17 | public AnimalType Type { get; set; } 18 | public string Name { get; set; } 19 | 20 | public Pet(string petName) 21 | { 22 | this.Name = petName; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace WorkSpace 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Samples/WorkSpace/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("Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("1d621566-6326-4298-90cd-9dd0c310ed25")] 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/WorkSpace/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 WorkSpace.Properties 12 | { 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 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 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 WorkSpace.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/WorkSpace/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Samples/WorkSpace/WorkSpace.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1D621566-6326-4298-90CD-9DD0C310ED25} 8 | Exe 9 | Properties 10 | Test 11 | Test 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 41 | True 42 | 43 | 44 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll 45 | True 46 | 47 | 48 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll 49 | True 50 | 51 | 52 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll 53 | True 54 | 55 | 56 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll 57 | True 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Form 77 | 78 | 79 | Form1.cs 80 | 81 | 82 | 83 | 84 | 85 | 86 | Form1.cs 87 | 88 | 89 | ResXFileCodeGenerator 90 | Resources.Designer.cs 91 | Designer 92 | 93 | 94 | True 95 | Resources.resx 96 | 97 | 98 | 99 | SettingsSingleFileGenerator 100 | Settings.Designer.cs 101 | 102 | 103 | True 104 | Settings.settings 105 | True 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | {196653e2-638f-4590-82e6-79387f5b2fb9} 114 | P2PNET 115 | 116 | 117 | 118 | 125 | -------------------------------------------------------------------------------- /Samples/WorkSpace/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | --------------------------------------------------------------------------------