├── .travis.yml ├── global.json ├── Build.bat ├── References └── BouncyCastle │ ├── SL40 │ └── BouncyCastle.Crypto.dll │ ├── SL50 │ └── BouncyCastle.Crypto.dll │ ├── WP71 │ └── BouncyCastle.Crypto.dll │ └── WP80 │ └── BouncyCastle.Crypto.dll ├── MakeNugetPackage.bat ├── packages.SuperSocket.ClientEngine.Net20.config ├── packages.SuperSocket.ClientEngine.WP80.config ├── packages.SuperSocket.ClientEngine.MonoTouch.config ├── packages.SuperSocket.ClientEngine.Net35.config ├── packages.SuperSocket.ClientEngine.Net40.config ├── packages.SuperSocket.ClientEngine.MonoDroid.config ├── Core ├── IBufferSetter.cs ├── DataEventArgs.cs ├── ErrorEventArgs.cs ├── Properties │ ├── AssemblyInfo.Net40.cs │ ├── AssemblyInfo.Net45.cs │ ├── AssemblyInfo.Net20.cs │ ├── AssemblyInfo.Net35.cs │ ├── AssemblyInfo.WP71.cs │ ├── AssemblyInfo.WP80.cs │ ├── AssemblyInfo.MonoDroid.cs │ ├── AssemblyInfo.MonoTouch.cs │ ├── AssemblyInfo.SL40.cs │ ├── AssemblyInfo.SL50.cs │ └── AssemblyInfo.iOS.cs ├── SecurityOption.Silverlight.cs ├── IClientSession.cs ├── ConcurrentQueue.cs ├── NegotiateStreamTcpSession.cs ├── SecurityOption.cs ├── Core.WP71.csproj ├── ClientSession.cs └── SslStreamTcpSession.cs ├── packages.SuperSocket.ClientEngine.SL50.config ├── Common ├── ExtensionAttribute.cs ├── IProxyConnector.cs ├── GenericDelegates.Action.cs ├── Properties │ ├── AssemblyInfo.Net20.cs │ ├── AssemblyInfo.Net35.cs │ ├── AssemblyInfo.Net40.cs │ ├── AssemblyInfo.Net45.cs │ ├── AssemblyInfo.MonoDroid.cs │ ├── AssemblyInfo.MonoTouch.cs │ ├── AssemblyInfo.SL40.cs │ ├── AssemblyInfo.SL50.cs │ ├── AssemblyInfo.iOS.cs │ ├── AssemblyInfo.WP71.cs │ └── AssemblyInfo.WP80.cs ├── SearchMarkState.cs ├── DnsEndPoint.cs ├── GenericDelegates.Func.cs ├── ConnectAsyncExtension.WindowsPhone.cs ├── ConnectAsyncExtension.Silverlight.cs ├── GenericDelegates.cs.txt ├── ConnectAsyncExtension.Net35.cs ├── PosList.cs ├── ProxyEventArgs.cs ├── IBatchQueue.cs ├── ConnectAsyncExtension.cs ├── NameValueCollection.cs ├── ConnectAsyncExtension.Net45.cs ├── ConnectAsyncExtension.Net40.cs └── Common.WP71.csproj ├── Properties ├── AssemblyInfo.Net20.cs ├── AssemblyInfo.Net35.cs ├── AssemblyInfo.Net40.cs ├── AssemblyInfo.Net45.cs ├── AssemblyInfo.MonoDroid.cs ├── AssemblyInfo.MonoTouch.cs ├── AssemblyInfo.SL50.cs ├── AssemblyInfo.SL40.cs ├── AssemblyInfo.iOS.cs ├── AssemblyInfo.UWP.cs ├── AssemblyInfo.WP80.cs └── SuperSocket.ClientEngine.rd.xml ├── Test ├── .vscode │ ├── tasks.json │ └── launch.json ├── HttpPackageInfo.cs ├── FakeReceiveFilter.cs ├── HttpBodyReceiveFilter.cs ├── Test.csproj ├── HttpReceiveFilter.cs ├── HttpTest.cs ├── HttpConnectProxyTest.cs ├── BasicTest.cs ├── SearchMarkTest.cs └── HttpChunkReceiveFilter.cs ├── Proxy ├── Properties │ ├── AssemblyInfo.Net20.cs │ ├── AssemblyInfo.Net35.cs │ ├── AssemblyInfo.Net40.cs │ ├── AssemblyInfo.Net45.cs │ ├── AssemblyInfo.MonoDroid.cs │ ├── AssemblyInfo.MonoTouch.cs │ ├── AssemblyInfo.SL40.cs │ ├── AssemblyInfo.SL50.cs │ ├── AssemblyInfo.WP71.cs │ ├── AssemblyInfo.WP80.cs │ └── AssemblyInfo.iOS.cs ├── Proxy.WP71.csproj ├── Socks4aConnector.cs └── ProxyConnectorBase.cs ├── Protocol ├── Properties │ ├── AssemblyInfo.Net40.cs │ ├── AssemblyInfo.Net45.cs │ ├── AssemblyInfo.Net20.cs │ ├── AssemblyInfo.Net35.cs │ ├── AssemblyInfo.MonoDroid.cs │ ├── AssemblyInfo.MonoTouch.cs │ ├── AssemblyInfo.WP71.cs │ ├── AssemblyInfo.WP80.cs │ ├── AssemblyInfo.iOS.cs │ ├── AssemblyInfo.SL40.cs │ └── AssemblyInfo.SL50.cs ├── ICommand.cs ├── DelegateCommand.cs ├── Protocol.WP71.csproj └── AssemblyUtil.cs ├── SuperSocket.ClientEngine.UWP.project.json ├── Func.cs ├── PackageEventArgs.cs ├── GlobalAssemblyInfo.cs ├── packages.SuperSocket.ClientEngine.Net45.config ├── packages.SuperSocket.ClientEngine.iOS.config ├── .gitignore ├── SuperSocket.ClientEngine.Silverlight.sln ├── EasyClient.cs ├── SuperSocket.ClientEngine.WP80.sln ├── SuperSocket.ClientEngine.UWP.sln ├── SuperSocket.ClientEngine.nuspec ├── SuperSocket.ClientEngine.Xamarin.sln ├── SuperSocket.ClientEngine.Core.nuspec ├── SuperSocket.ClientEngine.WP71.sln ├── SuperSocket.ClientEngine.Net.sln ├── .gitattributes ├── README.md ├── LINQ.cs ├── SuperSocket.ClientEngine └── SuperSocket.ClientEngine.csproj ├── SuperSocket.ClientEngine.Core └── SuperSocket.ClientEngine.Core.csproj ├── SuperSocket.ClientEngine.NetCore.sln ├── SuperSocket.ClientEngine.build ├── SuperSocket.ClientEngine.iOS.csproj ├── SuperSocket.ClientEngine.Net40.csproj ├── SuperSocket.ClientEngine.MonoDroid.csproj ├── SuperSocket.ClientEngine.Net45.csproj ├── SuperSocket.ClientEngine.Net35.csproj ├── SuperSocket.ClientEngine.Net20.csproj ├── SuperSocket.ClientEngine.MonoTouch.csproj ├── SuperSocket.ClientEngine.SL40.csproj └── SuperSocket.ClientEngine.SL50.csproj /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | solution: SuperSocket.ClientEngine.Net.sln -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ 3 | ".", "SuperSocket.ClientEngine", "Test" 4 | ], 5 | "sdk": { 6 | "version": "1.0.1" 7 | } 8 | } -------------------------------------------------------------------------------- /Build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set msbuild="%ProgramFiles(x86)%\MSBuild\14.0\Bin\msbuild.exe" 4 | 5 | %msbuild% SuperSocket.ClientEngine.build /t:Build 6 | 7 | pause -------------------------------------------------------------------------------- /References/BouncyCastle/SL40/BouncyCastle.Crypto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerryjiang/SuperSocket.ClientEngine/HEAD/References/BouncyCastle/SL40/BouncyCastle.Crypto.dll -------------------------------------------------------------------------------- /References/BouncyCastle/SL50/BouncyCastle.Crypto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerryjiang/SuperSocket.ClientEngine/HEAD/References/BouncyCastle/SL50/BouncyCastle.Crypto.dll -------------------------------------------------------------------------------- /References/BouncyCastle/WP71/BouncyCastle.Crypto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerryjiang/SuperSocket.ClientEngine/HEAD/References/BouncyCastle/WP71/BouncyCastle.Crypto.dll -------------------------------------------------------------------------------- /References/BouncyCastle/WP80/BouncyCastle.Crypto.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerryjiang/SuperSocket.ClientEngine/HEAD/References/BouncyCastle/WP80/BouncyCastle.Crypto.dll -------------------------------------------------------------------------------- /MakeNugetPackage.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set msbuild="%ProgramFiles(x86)%\MSBuild\14.0\Bin\msbuild.exe" 4 | 5 | %msbuild% SuperSocket.ClientEngine.build /t:BuildAndPack 6 | 7 | pause -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.Net20.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.WP80.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.MonoTouch.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.Net35.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.Net40.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.MonoDroid.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Core/IBufferSetter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | public interface IBufferSetter 8 | { 9 | void SetBuffer(ArraySegment bufferSegment); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.SL50.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Common/ExtensionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System.Runtime.CompilerServices 6 | { 7 | [AttributeUsage(AttributeTargets.Method)] 8 | public sealed class ExtensionAttribute : Attribute 9 | { 10 | public ExtensionAttribute() { } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.Net20.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for .NET 2.0")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.Net35.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for .NET 3.5")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.Net40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for .NET 4.0")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.Net45.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for .NET 4.5")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.MonoDroid.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for MonoDroid")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.MonoTouch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for MonoTouch")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.SL50.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for Silverlight 5.0")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Test/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [], 10 | "isBuildCommand": true, 11 | "problemMatcher": "$msCompile" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /Common/IProxyConnector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace SuperSocket.ClientEngine 7 | { 8 | public interface IProxyConnector 9 | { 10 | void Connect(EndPoint remoteEndPoint); 11 | 12 | event EventHandler Completed; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.SL40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for Silverlight 4.0")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] 9 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.iOS.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | 6 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 7 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for iOS Unified API")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.UWP.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | 6 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 7 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for Universal Windows Platform")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Properties/AssemblyInfo.WP80.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine for Windows Phone 8.1 Silverlight")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Common/GenericDelegates.Action.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System 6 | { 7 | public delegate void Action(T1 t1, T2 t2); 8 | 9 | public delegate void Action(T1 t1, T2 t2, T3 t3); 10 | 11 | public delegate void Action(T1 t1, T2 t2, T3 t3, T4 t4); 12 | } 13 | -------------------------------------------------------------------------------- /Core/DataEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | public class DataEventArgs : EventArgs 8 | { 9 | public byte[] Data { get; set; } 10 | 11 | public int Offset { get; set; } 12 | 13 | public int Length { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Test/HttpPackageInfo.cs: -------------------------------------------------------------------------------- 1 | using SuperSocket.ProtoBase; 2 | 3 | namespace SuperSocket.ClientEngine.Test 4 | { 5 | public class HttpPackageInfo : HttpPackageInfoBase 6 | { 7 | public HttpPackageInfo(string key, HttpHeaderInfo header, string body) 8 | : base(key, header, body) 9 | { 10 | 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.Net20.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for .Net 2.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("FA6E7187-ED6E-4BD6-831D-E29CD218E945")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.Net35.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for .Net 3.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("A08E3C10-0339-4D7E-9C58-AC1C74D5B643")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.Net40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for .Net 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("3cf45f04-d204-4967-83ea-6736a1e35754")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.Net45.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for .Net 4.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("3cf45f04-d204-4967-83ea-6736a1e35754")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.Net20.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for .NET 2.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("2AA800FB-DB9C-4EBE-B961-C0E65373D63F")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.Net35.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for .NET 3.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("C818C776-929C-43E3-8866-60CBF8D0B407")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.Net40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for .NET 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("46e63a9d-166c-4b12-b171-2705f5f3dff9")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.Net45.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for .NET 4.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("46e63a9d-166c-4b12-b171-2705f5f3dff9")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.MonoDroid.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for MonoDroid")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("ADC5ED6A-69A1-4C15-8904-7A8628810587")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.MonoTouch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for MonoTouch")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("ADC5ED6A-69A1-4C15-8904-7A8628810587")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.SL40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for Silverlight 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("4E36DED6-3F7C-46FB-8E81-A779E3545180")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.SL50.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for Silverlight 5.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("0675E1D5-18C4-4B2B-85F5-B8A7FA831284")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.iOS.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for iOS Unified API")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("ADC5ED6A-69A1-4C15-8904-7A8628810587")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.MonoDroid.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for MonoDroid")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("84D7E6D8-350F-4FB7-8FF4-4D869A0537AF")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.MonoTouch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for MonoTouch")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("84D7E6D8-350F-4FB7-8FF4-4D869A0537AF")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.SL40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for Silverlight 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("7896A54D-2A3D-4F1D-9CA9-2B1BACC2B3F0")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.SL50.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for Silverlight 5.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("39E984C9-C19F-4B77-A6B3-F14F6E71A255")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.WP71.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for WindowsPhone 7.1")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("84C27621-48B1-4538-9813-AAF4EAA986BE")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.WP80.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for WindowsPhone 8.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("84C27621-48B1-4538-9813-AAF4EAA986BE")] 9 | -------------------------------------------------------------------------------- /Proxy/Properties/AssemblyInfo.iOS.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Proxy for iOS Unified API")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Proxy")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("84D7E6D8-350F-4FB7-8FF4-4D869A0537AF")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.WP71.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for WindowsPhone 7.1")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("7F46C704-3697-4BD9-BD32-FFFFD4157BCF")] 9 | -------------------------------------------------------------------------------- /Common/Properties/AssemblyInfo.WP80.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Common for WindowsPhone 8.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Common")] 7 | [assembly: ComVisible(false)] 8 | [assembly: Guid("7F46C704-3697-4BD9-BD32-FFFFD4157BCF")] 9 | -------------------------------------------------------------------------------- /Core/ErrorEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | public class ErrorEventArgs : EventArgs 8 | { 9 | public Exception Exception { get; private set; } 10 | 11 | public ErrorEventArgs(Exception exception) 12 | { 13 | Exception = exception; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.Net40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Core for .NET 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] 9 | [assembly: Guid("fbbb2183-5bc3-4bbe-8f09-eb2d55d97d72")] -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.Net45.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Core for .NET 4.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] 9 | [assembly: Guid("fbbb2183-5bc3-4bbe-8f09-eb2d55d97d72")] -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.Net40.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Protocol for .NET 4.0")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] 9 | [assembly: Guid("AAAD620D-6E44-40A5-9D50-6FB73EF0A4DC")] -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.Net45.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("SuperSocket.ClientEngine.Protocol for .NET 4.5")] 6 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: ComVisible(false)] 9 | [assembly: Guid("AAAD620D-6E44-40A5-9D50-6FB73EF0A4DC")] -------------------------------------------------------------------------------- /Core/SecurityOption.Silverlight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace SuperSocket.ClientEngine 5 | { 6 | /// 7 | /// Security options 8 | /// 9 | public class SecurityOption 10 | { 11 | /// 12 | /// The SslProtocols want to be enabled 13 | /// 14 | public bool EnabledSslProtocols { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Common/SearchMarkState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | public class SearchMarkState 8 | where T : IEquatable 9 | { 10 | public SearchMarkState(T[] mark) 11 | { 12 | Mark = mark; 13 | } 14 | 15 | public T[] Mark { get; private set; } 16 | 17 | public int Matched { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common/DnsEndPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net; 5 | 6 | namespace System.Net 7 | { 8 | public class DnsEndPoint : EndPoint 9 | { 10 | public string Host { get; private set; } 11 | 12 | public int Port { get; private set; } 13 | 14 | public DnsEndPoint(string host, int port) 15 | { 16 | Host = host; 17 | Port = port; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.UWP.project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", 4 | "SuperSocket.ProtoBase": "1.7.0.17", 5 | "System.Collections.Specialized": "4.3.0" 6 | }, 7 | "frameworks": { 8 | "uap10.0": {} 9 | }, 10 | "runtimes": { 11 | "win10-arm": {}, 12 | "win10-arm-aot": {}, 13 | "win10-x86": {}, 14 | "win10-x86-aot": {}, 15 | "win10-x64": {}, 16 | "win10-x64-aot": {} 17 | } 18 | } -------------------------------------------------------------------------------- /Func.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System 6 | { 7 | public delegate TResult Func(); 8 | 9 | public delegate TResult Func(T t); 10 | 11 | public delegate TResult Func(T1 t1, T2 t2); 12 | 13 | public delegate TResult Func(T1 t1, T2 t2, T3 t3); 14 | 15 | public delegate TResult Func(T1 t1, T2 t2, T3 t3, T4 t4); 16 | } 17 | -------------------------------------------------------------------------------- /Common/GenericDelegates.Func.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System 6 | { 7 | public delegate TResult Func(); 8 | 9 | public delegate TResult Func(T t); 10 | 11 | public delegate TResult Func(T1 t1, T2 t2); 12 | 13 | public delegate TResult Func(T1 t1, T2 t2, T3 t3); 14 | 15 | public delegate TResult Func(T1 t1, T2 t2, T3 t3, T4 t4); 16 | } 17 | -------------------------------------------------------------------------------- /Test/FakeReceiveFilter.cs: -------------------------------------------------------------------------------- 1 | using SuperSocket.ProtoBase; 2 | 3 | namespace SuperSocket.ClientEngine.Test 4 | { 5 | public class FakeReceiveFilter : TerminatorReceiveFilter 6 | { 7 | public FakeReceiveFilter() 8 | : base(new byte[] { 0x01, 0x02 }) 9 | { 10 | 11 | } 12 | 13 | public override StringPackageInfo ResolvePackage(IBufferStream bufferStream) 14 | { 15 | return null; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PackageEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using SuperSocket.ProtoBase; 6 | 7 | namespace SuperSocket.ClientEngine 8 | { 9 | public class PackageEventArgs : EventArgs 10 | where TPackageInfo : IPackageInfo 11 | { 12 | public TPackageInfo Package { get; private set; } 13 | 14 | public PackageEventArgs(TPackageInfo package) 15 | { 16 | Package = package; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /GlobalAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyVersion("0.10.0.0")] 6 | [assembly: AssemblyFileVersion("0.10.0.0")] 7 | [assembly: AssemblyCompany("SuperSocket")] 8 | [assembly: AssemblyProduct("SuperSocket ClientEngine")] 9 | [assembly: AssemblyInformationalVersion("0.10.0.0")] 10 | [assembly: AssemblyCopyright("Copyright © www.supersocket.net 2018")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] -------------------------------------------------------------------------------- /Protocol/ICommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using SuperSocket.ProtoBase; 5 | 6 | namespace SuperSocket.ClientEngine.Protocol 7 | { 8 | public interface ICommand 9 | { 10 | string Name { get; } 11 | } 12 | 13 | public interface ICommand : ICommand 14 | where TPackageInfo : IPackageInfo 15 | where TSession : class 16 | { 17 | void ExecuteCommand(TSession session, TPackageInfo packageInfo); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.WindowsPhone.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Text; 5 | 6 | namespace SuperSocket.ClientEngine 7 | { 8 | public static partial class ConnectAsyncExtension 9 | { 10 | public static void ConnectAsync(this EndPoint remoteEndPoint, ConnectedCallback callback, object state) 11 | { 12 | var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); 13 | Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.Net45.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages.SuperSocket.ClientEngine.iOS.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.Net20.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("SuperSocket.ClientEngine.Core for .NET 2.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("977056B2-EC84-485D-BEE1-CF159AD97613")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.Net35.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("SuperSocket.ClientEngine.Core for .NET 3.5")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("7D0C5B57-780B-4598-8E31-67DAF8F28F8B")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.WP71.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("SuperSocket.ClientEngine.Core for Windows Phone 7.1")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("33F89486-B096-4EE6-8846-95237A39A37D")] -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.WP80.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("SuperSocket.ClientEngine.Core for Windows Phone 8.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("33F89486-B096-4EE6-8846-95237A39A37D")] -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.MonoDroid.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("SuperSocket.ClientEngine.Core for MonoDroid")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("B63E175D-AC4D-4B84-A1C2-82CAEE84BAE2")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.MonoTouch.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("SuperSocket.ClientEngine.Core for MonoTouch")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("B63E175D-AC4D-4B84-A1C2-82CAEE84BAE2")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.SL40.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("SuperSocket.ClientEngine.Core for Silverlight 4.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("7FBCB35D-C26B-454A-8ED0-C11A0F5493C6")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.SL50.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("SuperSocket.ClientEngine.Core for Silverlight 5.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("7FBCB35D-C26B-454A-8ED0-C11A0F5493C6")] 13 | -------------------------------------------------------------------------------- /Core/Properties/AssemblyInfo.iOS.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("SuperSocket.ClientEngine.Core for iOS Unified API")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Core")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("B63E175D-AC4D-4B84-A1C2-82CAEE84BAE2")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.Net20.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("SuperSocket.ClientEngine.Protocol for .NET 2.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("F14BA4B2-06FF-4679-BD86-66BD3F94AE3F")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.Net35.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("SuperSocket.ClientEngine.Protocol for .NET 3.5")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("8BA03C1B-64D8-405F-978A-46C217C2A97C")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.MonoDroid.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("SuperSocket.ClientEngine.Protocol for MonoDroid")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("C24F2E17-F718-4A4B-BD37-F2D4BE8B8434")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.MonoTouch.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("SuperSocket.ClientEngine.Protocol for MonoTouch")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("C24F2E17-F718-4A4B-BD37-F2D4BE8B8434")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.WP71.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("SuperSocket.ClientEngine.Protocol for Windows Phone 7.1")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("32989C43-E19F-4DB7-9999-A21C30C5F09D")] -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.WP80.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("SuperSocket.ClientEngine.Protocol for Windows Phone 8.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("32989C43-E19F-4DB7-9999-A21C30C5F09D")] -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.iOS.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("SuperSocket.ClientEngine.Protocol for iOS Unified API")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("C24F2E17-F718-4A4B-BD37-F2D4BE8B8434")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.SL40.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("SuperSocket.ClientEngine.Protocol for Silverlight 4.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("EBC11FC8-867B-411D-8DC6-1BF1D436A3B6")] 13 | -------------------------------------------------------------------------------- /Protocol/Properties/AssemblyInfo.SL50.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("SuperSocket.ClientEngine.Protocol for Silverlight 5.0")] 9 | [assembly: AssemblyDescription("SuperSocket.ClientEngine.Protocol")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: ComVisible(false)] 12 | [assembly: Guid("CC5AFD2D-254F-47FF-9DC0-BBA0E8F47E72")] 13 | -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.Silverlight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.Sockets; 4 | using System.Text; 5 | 6 | namespace SuperSocket.ClientEngine 7 | { 8 | public static partial class ConnectAsyncExtension 9 | { 10 | public static void ConnectAsync(this EndPoint remoteEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, ConnectedCallback callback, object state) 11 | { 12 | var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); 13 | e.SocketClientAccessPolicyProtocol = clientAccessPolicyProtocol; 14 | Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Common/GenericDelegates.cs.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System 6 | { 7 | public delegate void Action(T1 t1, T2 t2); 8 | 9 | public delegate void Action(T1 t1, T2 t2, T3 t3); 10 | 11 | public delegate void Action(T1 t1, T2 t2, T3 t3, T4 t4); 12 | 13 | public delegate TResult Func(); 14 | 15 | public delegate TResult Func(T t); 16 | 17 | public delegate TResult Func(T1 t1, T2 t2); 18 | 19 | public delegate TResult Func(T1 t1, T2 t2, T3 t3); 20 | 21 | public delegate TResult Func(T1 t1, T2 t2, T3 t3, T4 t4); 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | debug/ 3 | Bin/ 4 | Debug/ 5 | Thumbs.db 6 | *.obj 7 | *.exe 8 | *.pdb 9 | *.user 10 | *.aps 11 | *.pch 12 | *.vspscc 13 | *_i.c 14 | *_p.c 15 | *.ncb 16 | *.suo 17 | *.sln.docstates 18 | *.sln.docstates.suo 19 | *.tlb 20 | *.tlh 21 | *.bak 22 | *.cache 23 | *.ilk 24 | *.log 25 | *.lock.json 26 | [Bb]in 27 | [Dd]ebug*/ 28 | *.lib 29 | *.sbr 30 | obj/ 31 | [Rr]elease*/ 32 | _ReSharper*/ 33 | [Tt]est[Rr]esult* 34 | TempPE/ 35 | *.ncrunchsolution 36 | *.ncrunchsolution.user 37 | *.ncrunchproject 38 | *.userprefs 39 | ======= 40 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 41 | bin 42 | obj 43 | .DS_Store 44 | 45 | # mstest test results 46 | TestResults 47 | 48 | #Created by Visual Studio 49 | .vs 50 | 51 | #Created by NuGet 52 | packages 53 | *.nupkg -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.Net35.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace SuperSocket.ClientEngine 9 | { 10 | public static partial class ConnectAsyncExtension 11 | { 12 | public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) 13 | { 14 | ConnectAsyncInternal(remoteEndPoint, localEndPoint, callback, state); 15 | } 16 | 17 | static partial void CreateAttempSocket(DnsConnectState connectState) 18 | { 19 | if (Socket.OSSupportsIPv6) 20 | connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); 21 | 22 | connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Test/HttpBodyReceiveFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using SuperSocket.ProtoBase; 4 | 5 | namespace SuperSocket.ClientEngine.Test 6 | { 7 | public class HttpBodyReceiveFilter : FixedSizeReceiveFilter 8 | { 9 | private HttpHeaderInfo m_HttpHeader; 10 | 11 | private int m_HeaderSize; 12 | 13 | private int m_Size; 14 | 15 | public HttpBodyReceiveFilter(HttpHeaderInfo httpHeader, int size, int headerSize) 16 | : base(size) 17 | { 18 | m_HttpHeader = httpHeader; 19 | m_Size = size; 20 | m_HeaderSize = headerSize; 21 | } 22 | 23 | public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) 24 | { 25 | var total = (int)bufferStream.Length; 26 | return new HttpPackageInfo("Test", m_HttpHeader, bufferStream.Skip(m_HeaderSize).ReadString(total - m_HeaderSize, Encoding.UTF8)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Common/PosList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | /// 8 | /// The generic list interface with position 9 | /// 10 | /// 11 | public interface IPosList : IList 12 | { 13 | /// 14 | /// Gets or sets the position of current item. 15 | /// 16 | /// 17 | /// The position. 18 | /// 19 | int Position { get; set; } 20 | } 21 | 22 | /// 23 | /// The generic list with position 24 | /// 25 | /// 26 | public class PosList : List, IPosList 27 | { 28 | /// 29 | /// Gets or sets the position of current item. 30 | /// 31 | /// 32 | /// The position. 33 | /// 34 | public int Position { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Test/Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.0 5 | Test 6 | Library 7 | Test 8 | true 9 | 1.0.4 10 | $(PackageTargetFallback);dnxcore50;portable-net451+win8 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Protocol/DelegateCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using SuperSocket.ClientEngine; 5 | using SuperSocket.ProtoBase; 6 | 7 | namespace SuperSocket.ClientEngine.Protocol 8 | { 9 | public delegate void CommandDelegate(TClientSession session, TPackageInfo packageInfo); 10 | 11 | class DelegateCommand : ICommand 12 | where TClientSession : class 13 | where TPackageInfo : IPackageInfo 14 | { 15 | private CommandDelegate m_Execution; 16 | 17 | public DelegateCommand(string name, CommandDelegate execution) 18 | { 19 | Name = name; 20 | m_Execution = execution; 21 | } 22 | 23 | public void ExecuteCommand(TClientSession session, TPackageInfo packageInfo) 24 | { 25 | m_Execution(session, packageInfo); 26 | } 27 | 28 | public string Name { get; private set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Silverlight.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.SL50", "SuperSocket.ClientEngine.SL50.csproj", "{161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Core/IClientSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace SuperSocket.ClientEngine 9 | { 10 | public interface IClientSession 11 | { 12 | Socket Socket { get; } 13 | 14 | IProxyConnector Proxy { get; set; } 15 | 16 | int ReceiveBufferSize { get; set; } 17 | 18 | int SendingQueueSize { get; set; } 19 | 20 | bool IsConnected { get; } 21 | 22 | void Connect(EndPoint remoteEndPoint); 23 | 24 | void Send(ArraySegment segment); 25 | 26 | void Send(IList> segments); 27 | 28 | void Send(byte[] data, int offset, int length); 29 | 30 | bool TrySend(ArraySegment segment); 31 | 32 | bool TrySend(IList> segments); 33 | 34 | void Close(); 35 | 36 | event EventHandler Connected; 37 | 38 | event EventHandler Closed; 39 | 40 | event EventHandler Error; 41 | 42 | event EventHandler DataReceived; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Common/ProxyEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Net.Sockets; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | public class ProxyEventArgs : EventArgs 8 | { 9 | public ProxyEventArgs(Socket socket) 10 | : this(true, socket, null, null) 11 | { 12 | 13 | } 14 | 15 | public ProxyEventArgs(Socket socket, string targetHostHame) 16 | : this(true, socket, targetHostHame, null) 17 | { 18 | 19 | } 20 | 21 | public ProxyEventArgs(Exception exception) 22 | : this(false, null, null, exception) 23 | { 24 | 25 | } 26 | 27 | public ProxyEventArgs(bool connected, Socket socket, string targetHostName, Exception exception) 28 | { 29 | Connected = connected; 30 | Socket = socket; 31 | TargetHostName = targetHostName; 32 | Exception = exception; 33 | } 34 | 35 | public bool Connected { get; private set; } 36 | 37 | public Socket Socket { get; private set; } 38 | 39 | public Exception Exception { get; private set; } 40 | 41 | public string TargetHostName { get; private set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Test/HttpReceiveFilter.cs: -------------------------------------------------------------------------------- 1 | using SuperSocket.ProtoBase; 2 | using System; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine.Test 6 | { 7 | public class HttpReceiveFilter : HttpHeaderReceiveFilterBase 8 | { 9 | protected override IReceiveFilter GetBodyReceiveFilter(HttpHeaderInfo header, int headerSize) 10 | { 11 | 12 | var contentLength = 0; 13 | var strContentLength = header.Get("Content-Length"); 14 | 15 | if (string.IsNullOrEmpty(strContentLength)) 16 | contentLength = -1; 17 | else 18 | contentLength = int.Parse(strContentLength); 19 | 20 | if (contentLength > 0) 21 | { 22 | var totalLength = headerSize + contentLength; 23 | return new HttpBodyReceiveFilter(header, totalLength, headerSize); 24 | } 25 | 26 | return new HttpChunkReceiveFilter(header, new StringBuilder()); 27 | } 28 | 29 | protected override HttpPackageInfo ResolveHttpPackageWithoutBody(HttpHeaderInfo header) 30 | { 31 | return new HttpPackageInfo("Test", header, string.Empty); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/ConcurrentQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Collections.Generic; 4 | 5 | namespace System.Collections.Concurrent 6 | { 7 | public class ConcurrentQueue 8 | { 9 | private Queue m_Queue; 10 | 11 | private object m_SyncRoot = new object(); 12 | 13 | public ConcurrentQueue() 14 | { 15 | m_Queue = new Queue(); 16 | } 17 | 18 | public ConcurrentQueue(int capacity) 19 | { 20 | m_Queue = new Queue(capacity); 21 | } 22 | 23 | public ConcurrentQueue(IEnumerable collection) 24 | { 25 | m_Queue = new Queue(collection); 26 | } 27 | 28 | public void Enqueue(T item) 29 | { 30 | lock (m_SyncRoot) 31 | { 32 | m_Queue.Enqueue(item); 33 | } 34 | } 35 | 36 | public bool TryDequeue(out T item) 37 | { 38 | lock (m_SyncRoot) 39 | { 40 | if (m_Queue.Count <= 0) 41 | { 42 | item = default(T); 43 | return false; 44 | } 45 | 46 | item = m_Queue.Dequeue(); 47 | return true; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Common/IBatchQueue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SuperSocket.ClientEngine 6 | { 7 | /// 8 | /// A queue interface which can operate in batch 9 | /// 10 | /// 11 | public interface IBatchQueue 12 | { 13 | /// 14 | /// Enqueues the specified item. 15 | /// 16 | /// The item. 17 | bool Enqueue(T item); 18 | 19 | /// 20 | /// Enqueues the specified items. 21 | /// 22 | /// The items. 23 | bool Enqueue(IList items); 24 | 25 | /// 26 | /// Tries to dequeue all items in the queue into the output list. 27 | /// 28 | /// The output items. 29 | /// 30 | bool TryDequeue(IList outputItems); 31 | 32 | /// 33 | /// Gets a value indicating whether this instance is empty. 34 | /// 35 | /// 36 | /// true if this instance is empty; otherwise, false. 37 | /// 38 | bool IsEmpty { get; } 39 | 40 | /// 41 | /// Gets the count. 42 | /// 43 | int Count { get; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net.Sockets; 5 | using System.Reflection; 6 | using System.Net; 7 | 8 | namespace SuperSocket.ClientEngine 9 | { 10 | public delegate void ConnectedCallback(Socket socket, object state, SocketAsyncEventArgs e, Exception exception); 11 | 12 | public static partial class ConnectAsyncExtension 13 | { 14 | class ConnectToken 15 | { 16 | public object State { get; set; } 17 | 18 | public ConnectedCallback Callback { get; set; } 19 | } 20 | 21 | static void SocketAsyncEventCompleted(object sender, SocketAsyncEventArgs e) 22 | { 23 | e.Completed -= SocketAsyncEventCompleted; 24 | var token = (ConnectToken)e.UserToken; 25 | e.UserToken = null; 26 | token.Callback(sender as Socket, token.State, e, null); 27 | } 28 | 29 | static SocketAsyncEventArgs CreateSocketAsyncEventArgs(EndPoint remoteEndPoint, ConnectedCallback callback, object state) 30 | { 31 | var e = new SocketAsyncEventArgs(); 32 | 33 | e.UserToken = new ConnectToken 34 | { 35 | State = state, 36 | Callback = callback 37 | }; 38 | 39 | e.RemoteEndPoint = remoteEndPoint; 40 | e.Completed += new EventHandler(SocketAsyncEventCompleted); 41 | 42 | return e; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Core/NegotiateStreamTcpSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Net.Security; 7 | using System.Threading; 8 | using System.Security.Authentication; 9 | using System.Threading.Tasks; 10 | 11 | namespace SuperSocket.ClientEngine 12 | { 13 | public class NegotiateStreamTcpSession : AuthenticatedStreamTcpSession 14 | { 15 | protected override void StartAuthenticatedStream(Socket client) 16 | { 17 | var securityOption = Security; 18 | 19 | if (securityOption == null) 20 | { 21 | throw new Exception("securityOption was not configured"); 22 | } 23 | 24 | var stream = new NegotiateStream(new NetworkStream(client)); 25 | 26 | var credential = securityOption.Credential; 27 | 28 | if (credential == null) 29 | credential = (NetworkCredential)CredentialCache.DefaultCredentials; 30 | 31 | Task.Run(async () => 32 | { 33 | try 34 | { 35 | await stream.AuthenticateAsClientAsync(credential, HostName); 36 | } 37 | catch(Exception e) 38 | { 39 | EnsureSocketClosed(); 40 | OnError(e); 41 | return; 42 | } 43 | 44 | OnAuthenticatedStreamConnected(stream); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Properties/SuperSocket.ClientEngine.rd.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /EasyClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Text; 6 | using SuperSocket.ProtoBase; 7 | 8 | namespace SuperSocket.ClientEngine 9 | { 10 | public class EasyClient : EasyClientBase 11 | { 12 | private Action m_Handler; 13 | 14 | public void Initialize(IReceiveFilter receiveFilter, Action handler) 15 | where TPackageInfo : IPackageInfo 16 | { 17 | PipeLineProcessor = new DefaultPipelineProcessor(receiveFilter); 18 | m_Handler = (p) => handler((TPackageInfo)p); 19 | } 20 | 21 | protected override void HandlePackage(IPackageInfo package) 22 | { 23 | var handler = m_Handler; 24 | 25 | if (handler == null) 26 | return; 27 | 28 | handler(package); 29 | } 30 | } 31 | 32 | public class EasyClient : EasyClientBase 33 | where TPackageInfo : IPackageInfo 34 | { 35 | public event EventHandler> NewPackageReceived; 36 | 37 | public EasyClient() 38 | { 39 | 40 | } 41 | 42 | public virtual void Initialize(IReceiveFilter receiveFilter) 43 | { 44 | PipeLineProcessor = new DefaultPipelineProcessor(receiveFilter); 45 | } 46 | 47 | protected override void HandlePackage(IPackageInfo package) 48 | { 49 | var handler = NewPackageReceived; 50 | 51 | if (handler == null) 52 | return; 53 | 54 | handler(this, new PackageEventArgs((TPackageInfo)package)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.WP80.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.WP80", "SuperSocket.ClientEngine.WP80.csproj", "{AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|ARM = Debug|ARM 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|ARM = Release|ARM 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|ARM.Build.0 = Debug|ARM 22 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|x86.ActiveCfg = Debug|x86 23 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Debug|x86.Build.0 = Debug|x86 24 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|ARM.ActiveCfg = Release|ARM 27 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|ARM.Build.0 = Release|ARM 28 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|x86.ActiveCfg = Release|x86 29 | {AE1BD7FA-F487-4D8F-BD56-3E5E16FDEEE9}.Release|x86.Build.0 = Release|x86 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /Test/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (console)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/Test.dll", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "stopAtEntry": false 13 | }, 14 | { 15 | "name": ".NET Core Launch (web)", 16 | "type": "coreclr", 17 | "request": "launch", 18 | "preLaunchTask": "build", 19 | "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/Test.dll", 20 | "args": [], 21 | "cwd": "${workspaceRoot}", 22 | "stopAtEntry": false, 23 | "launchBrowser": { 24 | "enabled": true, 25 | "args": "${auto-detect-url}", 26 | "windows": { 27 | "command": "cmd.exe", 28 | "args": "/C start ${auto-detect-url}" 29 | }, 30 | "osx": { 31 | "command": "open" 32 | }, 33 | "linux": { 34 | "command": "xdg-open" 35 | } 36 | } 37 | }, 38 | { 39 | "name": ".NET Core Attach", 40 | "type": "coreclr", 41 | "request": "attach", 42 | "processName": "" 43 | }, 44 | { 45 | "name": ".NET Core Test", 46 | "type": "coreclr", 47 | "request": "launch", 48 | "preLaunchTask": "build", 49 | "program": "dotnet test", 50 | "args": [], 51 | "cwd": "${workspaceRoot}", 52 | "stopAtEntry": false 53 | } 54 | ] 55 | } -------------------------------------------------------------------------------- /Test/HttpTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Xunit; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | using System; 7 | using SuperSocket.ClientEngine; 8 | 9 | namespace SuperSocket.ClientEngine.Test 10 | { 11 | public class HttpTest 12 | { 13 | [Fact] 14 | public async Task TestGet() 15 | { 16 | var client = new EasyClient(); 17 | 18 | //client.Security = new SecurityOption(); 19 | //client.Security.AllowUnstrustedCertificate = true; 20 | //client.Security.AllowNameMismatchCertificate = true; 21 | 22 | client.Error += (s, e) => 23 | { 24 | Console.WriteLine(e.Exception.Message); 25 | }; 26 | 27 | var taskCompleteSrc = new TaskCompletionSource(); 28 | 29 | client.Initialize(new HttpReceiveFilter(), (p) => 30 | { 31 | taskCompleteSrc.SetResult(p); 32 | }); 33 | 34 | var ret = await client.ConnectAsync(new DnsEndPoint("www.supersocket.net", 80)); 35 | 36 | Assert.True(ret); 37 | Console.WriteLine("Get https connection established"); 38 | 39 | var sb = new StringBuilder(); 40 | 41 | sb.AppendLine("GET / HTTP/1.1"); 42 | sb.AppendLine("Accept: text/html, application/xhtml+xml, image/jxr, */*"); 43 | sb.AppendLine("Host: www.supersocket.net"); 44 | sb.AppendLine("Connection: Keep-Alive"); 45 | sb.AppendLine(); 46 | 47 | var data = Encoding.ASCII.GetBytes(sb.ToString()); 48 | 49 | client.Send(new ArraySegment(data, 0, data.Length)); 50 | 51 | var response = await taskCompleteSrc.Task; 52 | 53 | Console.WriteLine(response.Body); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Test/HttpConnectProxyTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Xunit; 3 | using System; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Collections.Generic; 7 | using SuperSocket.ProtoBase; 8 | using System.Text; 9 | using SuperSocket.ClientEngine.Proxy; 10 | using System.Threading; 11 | 12 | namespace SuperSocket.ClientEngine.Test 13 | { 14 | public class HttpConnectProxyTest 15 | { 16 | [Fact] 17 | public void TestMatchSecondTime() 18 | { 19 | var server = CreateSimplyRespond(Encoding.ASCII.GetBytes("OK")); 20 | var proxyServer = CreateSimplyRespond(Encoding.ASCII.GetBytes("OK")); 21 | 22 | ManualResetEvent wait = new ManualResetEvent(false); 23 | 24 | var proxy = new HttpConnectProxy(proxyServer.LocalEndPoint); 25 | ProxyEventArgs eventArgs = null; 26 | proxy.Completed += (a, e) => 27 | { 28 | eventArgs = e; 29 | wait.Set(); 30 | }; 31 | proxy.Connect(server.LocalEndPoint); 32 | 33 | Assert.True(wait.WaitOne(5000)); 34 | Assert.Null(eventArgs.Exception); 35 | Assert.True(eventArgs.Connected); 36 | } 37 | 38 | Socket CreateSimplyRespond(byte[] data) 39 | { 40 | var socket = NewTcpLocalBound(); 41 | Task.Run( 42 | () => 43 | { 44 | var stream = socket.Accept(); 45 | stream.Send(data); 46 | stream.Shutdown(SocketShutdown.Both); 47 | socket.Dispose(); 48 | } 49 | ); 50 | 51 | return socket; 52 | } 53 | 54 | Socket NewTcp() => new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 55 | 56 | Socket NewTcpLocalBound() 57 | { 58 | var socket = NewTcp(); 59 | socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); 60 | socket.Listen(1); 61 | return socket; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.UWP.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}") = "SuperSocket.ClientEngine.UWP", "SuperSocket.ClientEngine.UWP.csproj", "{801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|ARM = Debug|ARM 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|ARM = Release|ARM 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|ARM.ActiveCfg = Debug|ARM 23 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|ARM.Build.0 = Debug|ARM 24 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|x64.ActiveCfg = Debug|x64 25 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|x64.Build.0 = Debug|x64 26 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|x86.ActiveCfg = Debug|x86 27 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Debug|x86.Build.0 = Debug|x86 28 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|ARM.ActiveCfg = Release|ARM 31 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|ARM.Build.0 = Release|ARM 32 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|x64.ActiveCfg = Release|x64 33 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|x64.Build.0 = Release|x64 34 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|x86.ActiveCfg = Release|x86 35 | {801CE4E4-B1D9-40AA-AE30-B79466EBBD7D}.Release|x86.Build.0 = Release|x86 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SuperSocket.ClientEngine 5 | SuperSocket.ClientEngine, a socket client util 6 | $version$ 7 | Kerry Jiang 8 | Kerry Jiang 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | http://www.supersocket.net/ 11 | true 12 | It's a .NET socket tool which can simplify the socket client developing 13 | SuperSocket, Socket Client 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Common/NameValueCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace System.Collections.Specialized 6 | { 7 | public class NameValueCollection : List> 8 | { 9 | public new string this[int index] 10 | { 11 | get 12 | { 13 | return base[index].Value; 14 | } 15 | 16 | set 17 | { 18 | var oldKey = base[index].Key; 19 | base[index] = new KeyValuePair(oldKey, value); 20 | } 21 | } 22 | 23 | public string this[string name] 24 | { 25 | get 26 | { 27 | return this.SingleOrDefault(kv => kv.Key.Equals(name)).Value; 28 | } 29 | set 30 | { 31 | for (var i = 0; i < this.Count; i++) 32 | { 33 | if (name.Equals(this[i], StringComparison.OrdinalIgnoreCase)) 34 | { 35 | this.RemoveAt(i); 36 | break; 37 | } 38 | } 39 | 40 | this.Add(new KeyValuePair(name, value)); 41 | } 42 | } 43 | 44 | public NameValueCollection() 45 | { 46 | 47 | } 48 | 49 | public NameValueCollection(int capacity) 50 | : base(capacity) 51 | { 52 | 53 | } 54 | 55 | public void Add(string name, string value) 56 | { 57 | List> list = this; 58 | for (int i = Count - 1; i >= 0; --i) 59 | { 60 | if (string.Equals(list[i].Key, name)) 61 | { 62 | list[i] = new KeyValuePair(name, list[i].Value + "," + value); 63 | return; 64 | } 65 | } 66 | 67 | Add(new KeyValuePair(name, value)); 68 | } 69 | 70 | public IEnumerable AllKeys 71 | { 72 | get 73 | { 74 | return this.Select(pair => pair.Key); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.Net45.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Net.NetworkInformation; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | 7 | namespace SuperSocket.ClientEngine 8 | { 9 | public static partial class ConnectAsyncExtension 10 | { 11 | internal static bool PreferIPv4Stack() 12 | { 13 | return Environment.GetEnvironmentVariable("PREFER_IPv4_STACK") != null; 14 | } 15 | 16 | public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) 17 | { 18 | var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); 19 | 20 | #if NETSTANDARD 21 | 22 | if (localEndPoint != null) 23 | { 24 | var socket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); 25 | 26 | try 27 | { 28 | socket.ExclusiveAddressUse = false; 29 | socket.Bind(localEndPoint); 30 | } 31 | catch (Exception exc) 32 | { 33 | callback(null, state, null, exc); 34 | return; 35 | } 36 | 37 | socket.ConnectAsync(e); 38 | } 39 | else 40 | { 41 | Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); 42 | } 43 | #else 44 | var socket = PreferIPv4Stack() 45 | ? new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 46 | : new Socket(SocketType.Stream, ProtocolType.Tcp); 47 | 48 | if (localEndPoint != null) 49 | { 50 | try 51 | { 52 | socket.ExclusiveAddressUse = false; 53 | socket.Bind(localEndPoint); 54 | } 55 | catch (Exception exc) 56 | { 57 | callback(null, state, null, exc); 58 | return; 59 | } 60 | } 61 | 62 | socket.ConnectAsync(e); 63 | #endif 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Xamarin.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.MonoTouch", "SuperSocket.ClientEngine.MonoTouch.csproj", "{C3792DC0-53BF-44AF-B0FF-C6F5D3D09150}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.iOS", "SuperSocket.ClientEngine.iOS.csproj", "{248C3574-53DB-4C21-B58E-80CC99B3296C}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.MonoDroid", "SuperSocket.ClientEngine.MonoDroid.csproj", "{1FECD16C-D200-4184-B2DF-9A5DE15CD3B1}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {C3792DC0-53BF-44AF-B0FF-C6F5D3D09150}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {C3792DC0-53BF-44AF-B0FF-C6F5D3D09150}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {C3792DC0-53BF-44AF-B0FF-C6F5D3D09150}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {C3792DC0-53BF-44AF-B0FF-C6F5D3D09150}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {248C3574-53DB-4C21-B58E-80CC99B3296C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {248C3574-53DB-4C21-B58E-80CC99B3296C}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {248C3574-53DB-4C21-B58E-80CC99B3296C}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {248C3574-53DB-4C21-B58E-80CC99B3296C}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {1FECD16C-D200-4184-B2DF-9A5DE15CD3B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {1FECD16C-D200-4184-B2DF-9A5DE15CD3B1}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {1FECD16C-D200-4184-B2DF-9A5DE15CD3B1}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {1FECD16C-D200-4184-B2DF-9A5DE15CD3B1}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(MonoDevelopProperties) = preSolution 35 | StartupItem = Core\Core.MonoDroid.csproj 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SuperSocket.ClientEngine.Core 5 | SuperSocket.ClientEngine, a socket client util 6 | $version$ 7 | Kerry Jiang 8 | Kerry Jiang 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | http://www.supersocket.net/ 11 | true 12 | It's a .NET socket tool which can simplify the socket client developing. This difference between this package and SuperSocket.ClientEngine is it doesn't include the protocol resolving library. 13 | SuperSocket, Socket Client 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.WP71.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.WP71", "Core\Core.WP71.csproj", "{38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Protocol.WP71", "Protocol\Protocol.WP71.csproj", "{ECEC2C29-1E1E-48EF-B544-76510C2D42B9}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.WP71", "Common\Common.WP71.csproj", "{A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proxy.WP71", "Proxy\Proxy.WP71.csproj", "{0A32FF9D-87D3-4455-9BA9-20C915A1C7BE}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {ECEC2C29-1E1E-48EF-B544-76510C2D42B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {ECEC2C29-1E1E-48EF-B544-76510C2D42B9}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {ECEC2C29-1E1E-48EF-B544-76510C2D42B9}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {ECEC2C29-1E1E-48EF-B544-76510C2D42B9}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {0A32FF9D-87D3-4455-9BA9-20C915A1C7BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {0A32FF9D-87D3-4455-9BA9-20C915A1C7BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {0A32FF9D-87D3-4455-9BA9-20C915A1C7BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {0A32FF9D-87D3-4455-9BA9-20C915A1C7BE}.Release|Any CPU.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /Test/BasicTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Xunit; 3 | using System; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Collections.Generic; 7 | using SuperSocket.ProtoBase; 8 | 9 | namespace SuperSocket.ClientEngine.Test 10 | { 11 | public class BasicTest 12 | { 13 | [Fact] 14 | public async Task TestConnection() 15 | { 16 | var client = new EasyClient(); 17 | 18 | client.Initialize(new FakeReceiveFilter(), (p) => 19 | { 20 | // do nothing 21 | }); 22 | 23 | var ret = await client.ConnectAsync(new DnsEndPoint("github.com", 443)); 24 | 25 | Assert.True(ret); 26 | } 27 | 28 | [Fact] 29 | public async Task TestConnectRepeat() 30 | { 31 | var client = new EasyClient(); 32 | 33 | client.Initialize(new FakeReceiveFilter(), (p) => 34 | { 35 | // do nothing 36 | }); 37 | 38 | client.Error += (s, e) => 39 | { 40 | Console.WriteLine("Error:" + e.Exception.Message); 41 | }; 42 | 43 | Console.WriteLine("Connecting"); 44 | var ret = await client.ConnectAsync(new DnsEndPoint("github.com", 443)); 45 | Console.WriteLine("Connected"); 46 | Assert.True(ret); 47 | 48 | Console.WriteLine("Closing"); 49 | await client.Close(); 50 | Console.WriteLine("Closed"); 51 | 52 | Console.WriteLine("Connecting"); 53 | ret = await client.ConnectAsync(new DnsEndPoint("github.com", 443)); 54 | Console.WriteLine("Connected"); 55 | 56 | Assert.True(ret); 57 | 58 | Console.WriteLine("Closing"); 59 | await client.Close(); 60 | Console.WriteLine("Closed"); 61 | } 62 | 63 | [Fact] 64 | public void TestArraySegmentList() 65 | { 66 | var list = new BufferList(); 67 | 68 | list.Add(new ArraySegment(new byte[1024], 0, 100)); 69 | list.Add(new ArraySegment(new byte[1024], 2, 200)); 70 | list.Add(new ArraySegment(new byte[1024], 3, 300)); 71 | 72 | var lastOne = list.Last; 73 | 74 | Assert.Equal(3, lastOne.Offset); 75 | Assert.Equal(300, lastOne.Count); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Common/ConnectAsyncExtension.Net40.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Reflection; 7 | using System.Text; 8 | 9 | namespace SuperSocket.ClientEngine 10 | { 11 | public static partial class ConnectAsyncExtension 12 | { 13 | private static readonly MethodInfo m_ConnectMethod; 14 | 15 | private static bool m_OSSupportsIPv4; 16 | 17 | static ConnectAsyncExtension() 18 | { 19 | //.NET 4.0 has this method but Mono doesn't have 20 | m_ConnectMethod = typeof(Socket).GetMethod("ConnectAsync", BindingFlags.Public | BindingFlags.Static); 21 | 22 | //Socket.OSSupportsIPv4 doesn't exist in Mono 23 | var pro_OSSupportsIPv4 = typeof(Socket).GetProperty("OSSupportsIPv4", BindingFlags.Public | BindingFlags.Static); 24 | 25 | if (pro_OSSupportsIPv4 != null) 26 | { 27 | m_OSSupportsIPv4 = (bool)pro_OSSupportsIPv4.GetValue(null, new object[0]); 28 | } 29 | else 30 | { 31 | m_OSSupportsIPv4 = true; 32 | } 33 | } 34 | 35 | internal static bool PreferDnsInAdvance() 36 | { 37 | return Environment.GetEnvironmentVariable("PREFER_DNS_IN_ADVANCE") != null; 38 | } 39 | 40 | public static void ConnectAsync(this EndPoint remoteEndPoint, EndPoint localEndPoint, ConnectedCallback callback, object state) 41 | { 42 | //Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); 43 | //Don't use Socket.ConnectAsync directly because Mono hasn't implement this method 44 | if (m_ConnectMethod != null && localEndPoint == null && !PreferDnsInAdvance()) 45 | m_ConnectMethod.Invoke(null, new object[] { SocketType.Stream, ProtocolType.Tcp, CreateSocketAsyncEventArgs(remoteEndPoint, callback, state) }); 46 | else 47 | { 48 | ConnectAsyncInternal(remoteEndPoint, localEndPoint, callback, state); 49 | } 50 | } 51 | 52 | static partial void CreateAttempSocket(DnsConnectState connectState) 53 | { 54 | if (Socket.OSSupportsIPv6) 55 | connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); 56 | 57 | if (m_OSSupportsIPv4) 58 | connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Core/SecurityOption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Security.Authentication; 6 | using System.Security.Cryptography.X509Certificates; 7 | using System.Text; 8 | 9 | namespace SuperSocket.ClientEngine 10 | { 11 | /// 12 | /// Security options 13 | /// 14 | public class SecurityOption 15 | { 16 | /// 17 | /// The SslProtocols want to be enabled 18 | /// 19 | public SslProtocols EnabledSslProtocols { get; set; } 20 | 21 | /// 22 | /// Client X509 certificates 23 | /// 24 | public X509CertificateCollection Certificates { get; set; } 25 | 26 | /// 27 | /// Whether allow untrusted certificate 28 | /// 29 | public bool AllowUnstrustedCertificate { get; set; } 30 | 31 | /// 32 | /// Whether allow the certificate whose name doesn't match current remote endpoint's host name 33 | /// 34 | public bool AllowNameMismatchCertificate { get; set; } 35 | 36 | /// 37 | /// Whether allow the certificate chain errors 38 | /// 39 | public bool AllowCertificateChainErrors { get; set; } 40 | 41 | 42 | public NetworkCredential Credential { get; set; } 43 | 44 | 45 | public SecurityOption() 46 | : this(GetDefaultProtocol(), new X509CertificateCollection()) 47 | { 48 | 49 | } 50 | 51 | public SecurityOption(SslProtocols enabledSslProtocols) 52 | : this(enabledSslProtocols, new X509CertificateCollection()) 53 | { 54 | 55 | } 56 | 57 | public SecurityOption(SslProtocols enabledSslProtocols, X509Certificate certificate) 58 | : this(enabledSslProtocols, new X509CertificateCollection(new X509Certificate[] { certificate })) 59 | { 60 | 61 | } 62 | 63 | public SecurityOption(SslProtocols enabledSslProtocols, X509CertificateCollection certificates) 64 | { 65 | EnabledSslProtocols = enabledSslProtocols; 66 | Certificates = certificates; 67 | } 68 | 69 | public SecurityOption(NetworkCredential credential) 70 | { 71 | Credential = credential; 72 | } 73 | 74 | private static SslProtocols GetDefaultProtocol() 75 | { 76 | #if NETSTANDARD 77 | return SslProtocols.Tls11 | SslProtocols.Tls12; 78 | #else 79 | return SslProtocols.Default; 80 | #endif 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Net.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.Net45", "SuperSocket.ClientEngine.Net45.csproj", "{8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.Net40", "SuperSocket.ClientEngine.Net40.csproj", "{8BCA34D7-18E8-4B33-A102-9F0A3951B742}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.Net35", "SuperSocket.ClientEngine.Net35.csproj", "{8FD00E43-2FA2-47F4-9240-B77AE3426122}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.Net20", "SuperSocket.ClientEngine.Net20.csproj", "{377D2203-B53E-45B6-8593-D56F7D5B5DE8}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {8BCA34D7-18E8-4B33-A102-9F0A3951B742}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {8BCA34D7-18E8-4B33-A102-9F0A3951B742}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {8BCA34D7-18E8-4B33-A102-9F0A3951B742}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {8BCA34D7-18E8-4B33-A102-9F0A3951B742}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {8FD00E43-2FA2-47F4-9240-B77AE3426122}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {8FD00E43-2FA2-47F4-9240-B77AE3426122}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {8FD00E43-2FA2-47F4-9240-B77AE3426122}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {8FD00E43-2FA2-47F4-9240-B77AE3426122}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {377D2203-B53E-45B6-8593-D56F7D5B5DE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {377D2203-B53E-45B6-8593-D56F7D5B5DE8}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {377D2203-B53E-45B6-8593-D56F7D5B5DE8}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {377D2203-B53E-45B6-8593-D56F7D5B5DE8}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperSocket.ClientEngine [![Build Status](https://travis-ci.org/kerryjiang/SuperSocket.ClientEngine.svg?branch=master)](https://travis-ci.org/kerryjiang/SuperSocket.ClientEngine) [![NuGet Version](https://img.shields.io/nuget/v/SuperSocket.ClientEngine.svg?style=flat)](https://www.nuget.org/packages/SuperSocket.ClientEngine/) 2 | 3 | SuperSocket.ClientEngine is a .NET library for socket client rapid development. It provides easy to use and efficient APIs to simplify your socket development work about asynchronous connecting, data sending, data receiving, network protocol analysising and transfer layer encryption. 4 | 5 | ### Build from Source Code 6 | 7 | 1. Download source code from Github or clone the repository; 8 | 2. Restore dependencies using NuGet; (Latest NuGet Visual Studio extension will restore dependencies before build automatically. You also can follow [This NuGet doc](https://docs.nuget.org/consume/package-restore#package-restore-approaches) to do it manually.) 9 | 3. Choose a correct solution file to build; 10 | 11 | 12 | ### Install from NuGet 13 | 14 | PM> Install-Package SuperSocket.ClientEngine 15 | 16 | 17 | ### Usage 18 | 19 | 20 | #### Create your ReceiveFilter Implementation according Your Network Protocol 21 | 22 | SuperSocket.ClientEngine provides some powerfull basic ReceiveFilter classes (under the namespace "SuperSocket.ProtoBase") to help you simplify your protocol analysis: 23 | 24 | TerminatorReceiveFilter 25 | BeginEndMarkReceiveFilter 26 | FixedHeaderReceiveFilter 27 | FixedSizeReceiveFilter 28 | CountSpliterReceiveFilter 29 | 30 | You should design your own ReceiveFilter according yoru protocol details base on the basic ReceiveFilters provided by SuperSocket.ClientEngine: 31 | 32 | class MyReceiveFilter : TerminatorReceiveFilter 33 | { 34 | public MyReceiveFilter() 35 | : base(Encoding.ASCII.GetBytes("||")) // two vertical bars as package terminator 36 | { 37 | } 38 | 39 | // other code you need implement according yoru protocol details 40 | } 41 | 42 | 43 | #### Create an Instance of EasyClient and Initialize it with the ReceiveFilter which is created in the previous step 44 | 45 | var client = new EasyClient(); 46 | 47 | // Initialize the client with the receive filter and request handler 48 | client.Initialize(new MyReceiveFilter(), (request) => { 49 | // handle the received request 50 | Console.WriteLine(request.Key); 51 | }); 52 | 53 | 54 | #### Make a Connection and then Start the Communication 55 | 56 | 57 | // Connect to the server 58 | var connected = await client.ConnectAsync(new IPEndPoint(IPAddress.Parse("192.168.10.11"), 25)); 59 | 60 | if (connected) 61 | { 62 | // Send data to the server 63 | client.Send(Encoding.ASCII.GetBytes("LOGIN kerry")); 64 | } -------------------------------------------------------------------------------- /Test/SearchMarkTest.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Xunit; 3 | using System; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Collections.Generic; 7 | using SuperSocket.ProtoBase; 8 | using System.Text; 9 | 10 | namespace SuperSocket.ClientEngine.Test 11 | { 12 | public class SearchMarkTest 13 | { 14 | [Fact] 15 | public void TestMatchSecondTime() 16 | { 17 | byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n"); 18 | byte[] second = Encoding.ASCII.GetBytes("\r\n"); 19 | 20 | byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n"); 21 | 22 | // -2 means "\r\n\r\n" is partially matched at last 2 bytes 23 | Assert.Equal(-2, first.SearchMark(0, first.Length, mark)); 24 | 25 | // 0 means later part of "\r\n\r\n" is fully matched at 0 26 | Assert.Equal(0, second.SearchMark(0, second.Length, mark, 2)); 27 | } 28 | 29 | [Fact] 30 | public void TestMatchFirstTime() 31 | { 32 | byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n\r\n"); 33 | 34 | byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n"); 35 | 36 | // "\r\n\r\n" is matched at first[35] to [38] 37 | Assert.Equal(35, first.SearchMark(0, first.Length, mark)); 38 | } 39 | 40 | [Fact] 41 | public void TestMatchFirstTimeWithSearchMarkState() 42 | { 43 | byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n\r\n"); 44 | 45 | byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n"); 46 | 47 | var searchState = new SearchMarkState(mark); 48 | 49 | // "\r\n\r\n" is matched at first[35] to [38] 50 | Assert.Equal(35, first.SearchMark(0, first.Length, searchState)); 51 | } 52 | 53 | [Fact] 54 | public void TestMatchSecondTimeWithSearchMarkState() 55 | { 56 | byte[] first = Encoding.ASCII.GetBytes("HTTP/1.0 200 Connection Established\r\n"); 57 | byte[] second = Encoding.ASCII.GetBytes("\r\n"); 58 | 59 | byte[] mark = Encoding.ASCII.GetBytes("\r\n\r\n"); 60 | 61 | var searchState = new SearchMarkState(mark); 62 | 63 | { 64 | // -1 means: not matched, or partially matched. 65 | Assert.Equal(-1, first.SearchMark(0, first.Length, searchState)); 66 | 67 | // Check if (1 <= searchState.Matched) in case of partial match. 68 | } 69 | { 70 | var prevMatched = searchState.Matched; 71 | Assert.Equal(prevMatched, 2); 72 | 73 | // "\r\n\r\n" is completely matched on second buffer at second[0] to [1]. 74 | Assert.Equal(0, second.SearchMark(0, second.Length, searchState)); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LINQ.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace System.Linq 6 | { 7 | public static class LINQ 8 | { 9 | public static int Count(this IEnumerable source, Predicate predicate) 10 | { 11 | int count = 0; 12 | 13 | foreach (var item in source) 14 | { 15 | if (predicate(item)) 16 | count++; 17 | } 18 | 19 | return count; 20 | } 21 | 22 | public static bool Contains(this IEnumerable source, TSource target) 23 | { 24 | foreach (var item in source) 25 | { 26 | if (item.Equals(target)) 27 | return true; 28 | } 29 | 30 | return false; 31 | } 32 | 33 | public static TSource FirstOrDefault(this IEnumerable source, Predicate predicate) 34 | { 35 | foreach (var item in source) 36 | { 37 | if (predicate(item)) 38 | return item; 39 | } 40 | 41 | return default(TSource); 42 | } 43 | 44 | public static int Sum(this IEnumerable source, Func getter) 45 | { 46 | int sum = 0; 47 | 48 | foreach (var item in source) 49 | { 50 | sum += getter(item); 51 | } 52 | 53 | return sum; 54 | } 55 | 56 | public static IEnumerable OrderByDescending(this IEnumerable source, Func getter) 57 | where TKey : IComparable 58 | { 59 | var items = new List(); 60 | 61 | foreach (var i in source) 62 | { 63 | items.Add(i); 64 | } 65 | 66 | items.Sort(new DelegateComparer(getter)); 67 | 68 | return items; 69 | } 70 | 71 | public static TSource[] ToArray(this IEnumerable source) 72 | { 73 | if (source is TSource[]) 74 | return source as TSource[]; 75 | 76 | var items = new List(); 77 | 78 | foreach (var i in source) 79 | { 80 | items.Add(i); 81 | } 82 | 83 | return items.ToArray(); 84 | } 85 | } 86 | 87 | class DelegateComparer : IComparer 88 | where TKey : IComparable 89 | { 90 | private Func m_Getter; 91 | 92 | public DelegateComparer(Func getter) 93 | { 94 | m_Getter = getter; 95 | } 96 | 97 | public int Compare(TSource x, TSource y) 98 | { 99 | return m_Getter(x).CompareTo(m_Getter(y)); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine/SuperSocket.ClientEngine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0.10.0.0 5 | netstandard1.3 6 | SuperSocket.ClientEngine 7 | SuperSocket.ClientEngine for .NET standard library 8 | Library 9 | SuperSocket.ClientEngine 10 | false 11 | false 12 | false 13 | false 14 | false 15 | false 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | $(DefineConstants);NETFX_CORE;NETSTANDARD;AWAIT 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Test/HttpChunkReceiveFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using SuperSocket.ProtoBase; 4 | 5 | namespace SuperSocket.ClientEngine.Test 6 | { 7 | public class HttpChunkReceiveFilter : TerminatorReceiveFilter 8 | { 9 | private HttpHeaderInfo m_HttpHeader; 10 | private StringBuilder m_BodyBuilder; 11 | public HttpChunkReceiveFilter(HttpHeaderInfo header, StringBuilder bodyBuilder) 12 | : base(new byte[] { 0x0d, 0x0a }) 13 | { 14 | m_HttpHeader = header; 15 | m_BodyBuilder = bodyBuilder; 16 | } 17 | 18 | public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) 19 | { 20 | var numLen = (int)(bufferStream.Length - 2); 21 | var chunkSize = 0; 22 | 23 | var chunksizeString = bufferStream.ReadString(numLen, Encoding.ASCII); 24 | Console.WriteLine("ChunkSizeStr:" + chunksizeString); 25 | chunkSize = Convert.ToInt32(chunksizeString, 16); 26 | 27 | Console.WriteLine($"ChunkSize: {chunkSize}"); 28 | bufferStream.Buffers.Clear(); 29 | NextReceiveFilter = new HttpChunkDataReceiveFilter(this, chunkSize + 2); 30 | return null; 31 | } 32 | 33 | class HttpChunkDataReceiveFilter : FixedSizeReceiveFilter 34 | { 35 | HttpChunkReceiveFilter m_ParentFilter; 36 | 37 | public HttpChunkDataReceiveFilter(HttpChunkReceiveFilter parentFilter, int chunkSize) 38 | : base(chunkSize) 39 | { 40 | m_ParentFilter = parentFilter; 41 | } 42 | 43 | public override HttpPackageInfo Filter(BufferList data, out int rest) 44 | { 45 | // get the previous length for comparing later 46 | var prevLen = m_ParentFilter.m_BodyBuilder.Length; 47 | 48 | var package = base.Filter(data, out rest); 49 | 50 | var currentLen = m_ParentFilter.m_BodyBuilder.Length; 51 | 52 | // if there is no data chunk parsed, no reset should be return, otherwise return the rest directly 53 | if (currentLen == prevLen) 54 | rest = 0; 55 | 56 | return package; 57 | } 58 | 59 | public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream) 60 | { 61 | var realChunkSize = this.Size - 2; 62 | 63 | if (realChunkSize == 0) 64 | { 65 | // last chunk 66 | var body = m_ParentFilter.m_BodyBuilder.ToString(); 67 | return new HttpPackageInfo("Test", m_ParentFilter.m_HttpHeader, body); 68 | } 69 | 70 | m_ParentFilter.m_BodyBuilder.Append(bufferStream.ReadString(realChunkSize, Encoding.UTF8)); 71 | Console.WriteLine("Part:" + m_ParentFilter.m_BodyBuilder.ToString()); 72 | NextReceiveFilter = m_ParentFilter; 73 | bufferStream.Buffers.Clear(); 74 | 75 | return null; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Proxy/Proxy.WP71.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {0A32FF9D-87D3-4455-9BA9-20C915A1C7BE} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine.Proxy 13 | SuperSocket.ClientEngine.Proxy 14 | WindowsPhone71 15 | Silverlight 16 | false 17 | true 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE;SILVERLIGHT;WINDOWS_PHONE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | GlobalAssemblyInfo.cs 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E} 56 | Common.WP71 57 | 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Core/SuperSocket.ClientEngine.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0.10.0.0 4 | netstandard1.3 5 | SuperSocket.ClientEngine 6 | SuperSocket.ClientEngine for .NET standard library 7 | Library 8 | SuperSocket.ClientEngine.Core 9 | false 10 | false 11 | false 12 | false 13 | false 14 | false 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | $(DefineConstants);NETFX_CORE;NETSTANDARD;AWAIT 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Common/Common.WP71.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine 13 | SuperSocket.ClientEngine.Common 14 | WindowsPhone71 15 | Silverlight 16 | false 17 | true 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE;SILVERLIGHT;WINDOWS_PHONE 34 | prompt 35 | 4 36 | 37 | 38 | true 39 | 40 | 41 | ..\SuperSocket.ClientEngine.snk 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | GlobalAssemblyInfo.cs 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 74 | -------------------------------------------------------------------------------- /Protocol/Protocol.WP71.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {ECEC2C29-1E1E-48EF-B544-76510C2D42B9} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine.Protocol 13 | SuperSocket.ClientEngine.Protocol 14 | WindowsPhone71 15 | Silverlight 16 | false 17 | true 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE;SILVERLIGHT;WINDOWS_PHONE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | GlobalAssemblyInfo.cs 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E} 61 | Common.WP71 62 | 63 | 64 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F} 65 | Core.WP71 66 | 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /Core/Core.WP71.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {38A1B75C-AD6C-40E3-9E35-B5F00AB2FF2F} 9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine 13 | SuperSocket.ClientEngine.Core 14 | WindowsPhone71 15 | Silverlight 16 | false 17 | true 18 | true 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;NO_SPINWAIT_CLASS 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE;SILVERLIGHT;WINDOWS_PHONE;NO_SPINWAIT_CLASS 34 | prompt 35 | 4 36 | 37 | 38 | 39 | ..\References\BouncyCastle\WP71\BouncyCastle.Crypto.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | GlobalAssemblyInfo.cs 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | {A7CD766F-4033-45DD-9E9A-7EEA1F5CD08E} 65 | Common.WP71 66 | 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.NetCore.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine", "SuperSocket.ClientEngine\SuperSocket.ClientEngine.csproj", "{982113B9-59EB-4A39-B8CD-0507085E0AF0}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperSocket.ClientEngine.Core", "SuperSocket.ClientEngine.Core\SuperSocket.ClientEngine.Core.csproj", "{D44058D3-B3FF-48E3-AF97-5F3E399E2F25}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{F80957AA-E61B-47B9-AA0D-4BBF03608EF8}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|x64.ActiveCfg = Debug|x64 28 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|x64.Build.0 = Debug|x64 29 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|x86.ActiveCfg = Debug|x86 30 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Debug|x86.Build.0 = Debug|x86 31 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|x64.ActiveCfg = Release|x64 34 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|x64.Build.0 = Release|x64 35 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|x86.ActiveCfg = Release|x86 36 | {982113B9-59EB-4A39-B8CD-0507085E0AF0}.Release|x86.Build.0 = Release|x86 37 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|x64.ActiveCfg = Debug|x64 40 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|x64.Build.0 = Debug|x64 41 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|x86.ActiveCfg = Debug|x86 42 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Debug|x86.Build.0 = Debug|x86 43 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|x64.ActiveCfg = Release|x64 46 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|x64.Build.0 = Release|x64 47 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|x86.ActiveCfg = Release|x86 48 | {D44058D3-B3FF-48E3-AF97-5F3E399E2F25}.Release|x86.Build.0 = Release|x86 49 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 50 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|Any CPU.Build.0 = Debug|Any CPU 51 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|x64.ActiveCfg = Debug|x64 52 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|x64.Build.0 = Debug|x64 53 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|x86.ActiveCfg = Debug|x86 54 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Debug|x86.Build.0 = Debug|x86 55 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|Any CPU.Build.0 = Release|Any CPU 57 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|x64.ActiveCfg = Release|x64 58 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|x64.Build.0 = Release|x64 59 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|x86.ActiveCfg = Release|x86 60 | {F80957AA-E61B-47B9-AA0D-4BBF03608EF8}.Release|x86.Build.0 = Release|x86 61 | EndGlobalSection 62 | EndGlobal 63 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.build: -------------------------------------------------------------------------------- 1 | 2 | 3 | Release 4 | ..\..\SignKeys\SuperSocket.ClientEngine.snk 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | true 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | false 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Proxy/Socks4aConnector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using SuperSocket.ClientEngine; 7 | 8 | namespace SuperSocket.ClientEngine.Proxy 9 | { 10 | public class Socks4aConnector : Socks4Connector 11 | { 12 | private static Random m_Random = new Random(); 13 | 14 | #if SILVERLIGHT && !WINDOWS_PHONE 15 | public Socks4aConnector(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, string userID) 16 | : base(proxyEndPoint, clientAccessPolicyProtocol, userID) 17 | { 18 | 19 | } 20 | #else 21 | public Socks4aConnector(EndPoint proxyEndPoint, string userID) 22 | : base(proxyEndPoint, userID) 23 | { 24 | 25 | } 26 | #endif 27 | 28 | public override void Connect(EndPoint remoteEndPoint) 29 | { 30 | DnsEndPoint targetEndPoint = remoteEndPoint as DnsEndPoint; 31 | 32 | if (targetEndPoint == null) 33 | { 34 | OnCompleted(new ProxyEventArgs(new Exception("The argument 'remoteEndPoint' must be a DnsEndPoint"))); 35 | return; 36 | } 37 | 38 | try 39 | { 40 | #if SILVERLIGHT && !WINDOWS_PHONE 41 | ProxyEndPoint.ConnectAsync(ClientAccessPolicyProtocol, ProcessConnect, targetEndPoint); 42 | #elif WINDOWS_PHONE 43 | ProxyEndPoint.ConnectAsync(ProcessConnect, remoteEndPoint); 44 | #else 45 | ProxyEndPoint.ConnectAsync(null, ProcessConnect, targetEndPoint); 46 | #endif 47 | } 48 | catch (Exception e) 49 | { 50 | OnException(new Exception("Failed to connect proxy server", e)); 51 | } 52 | } 53 | 54 | protected override byte[] GetSendingBuffer(EndPoint targetEndPoint, out int actualLength) 55 | { 56 | var targetDnsEndPoint = targetEndPoint as DnsEndPoint; 57 | 58 | //The buffer size should be larger than 8, because it is required for receiving 59 | var bufferLength = Math.Max(8, (string.IsNullOrEmpty(UserID) ? 0 : ASCIIEncoding.GetMaxByteCount(UserID.Length)) + 5 + 4 + ASCIIEncoding.GetMaxByteCount(targetDnsEndPoint.Host.Length) + 1); 60 | var handshake = new byte[bufferLength]; 61 | 62 | handshake[0] = 0x04; 63 | handshake[1] = 0x01; 64 | 65 | handshake[2] = (byte)(targetDnsEndPoint.Port / 256); 66 | handshake[3] = (byte)(targetDnsEndPoint.Port % 256); 67 | 68 | handshake[4] = 0x00; 69 | handshake[5] = 0x00; 70 | handshake[6] = 0x00; 71 | handshake[7] = (byte)m_Random.Next(1, 255); 72 | 73 | actualLength = 8; 74 | 75 | if (!string.IsNullOrEmpty(UserID)) 76 | { 77 | actualLength += ASCIIEncoding.GetBytes(UserID, 0, UserID.Length, handshake, actualLength); 78 | } 79 | 80 | handshake[actualLength++] = 0x00; 81 | 82 | actualLength += ASCIIEncoding.GetBytes(targetDnsEndPoint.Host, 0, targetDnsEndPoint.Host.Length, handshake, actualLength); 83 | handshake[actualLength++] = 0x00; 84 | 85 | return handshake; 86 | } 87 | 88 | protected override void HandleFaultStatus(byte status) 89 | { 90 | string message = string.Empty; 91 | 92 | switch (status) 93 | { 94 | case (0x5b): 95 | message = "request rejected or failed"; 96 | break; 97 | case (0x5c): 98 | message = "request failed because client is not running identd (or not reachable from the server)"; 99 | break; 100 | case (0x5d): 101 | message = "request failed because client's identd could not confirm the user ID string in the reques"; 102 | break; 103 | default: 104 | message = "request rejected for unknown error"; 105 | break; 106 | } 107 | 108 | OnException(message); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {248C3574-53DB-4C21-B58E-80CC99B3296C} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Library 9 | SuperSocket.ClientEngine 10 | Resources 11 | SuperSocket.ClientEngine 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhone\Debug 18 | DEBUG;AWAIT 19 | prompt 20 | 4 21 | false 22 | true 23 | iPhone Developer 24 | 25 | 26 | none 27 | true 28 | bin\iPhone\Release 29 | prompt 30 | 4 31 | false 32 | iPhone Developer 33 | AWAIT 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\netstandard1.1\SuperSocket.ProtoBase.dll 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | -------------------------------------------------------------------------------- /Proxy/ProxyConnectorBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using SuperSocket.ClientEngine; 6 | 7 | namespace SuperSocket.ClientEngine.Proxy 8 | { 9 | public abstract class ProxyConnectorBase : IProxyConnector 10 | { 11 | public EndPoint ProxyEndPoint { get; private set; } 12 | 13 | public string TargetHostHame { get; private set; } 14 | 15 | protected static Encoding ASCIIEncoding = new ASCIIEncoding(); 16 | 17 | #if SILVERLIGHT && !WINDOWS_PHONE 18 | protected SocketClientAccessPolicyProtocol ClientAccessPolicyProtocol { get; private set; } 19 | 20 | public ProxyConnectorBase(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol) 21 | { 22 | ProxyEndPoint = proxyEndPoint; 23 | ClientAccessPolicyProtocol = clientAccessPolicyProtocol; 24 | } 25 | 26 | #else 27 | public ProxyConnectorBase(EndPoint proxyEndPoint) 28 | : this(proxyEndPoint, null) 29 | { 30 | 31 | } 32 | public ProxyConnectorBase(EndPoint proxyEndPoint, string targetHostHame) 33 | { 34 | ProxyEndPoint = proxyEndPoint; 35 | TargetHostHame = targetHostHame; 36 | } 37 | #endif 38 | 39 | public abstract void Connect(EndPoint remoteEndPoint); 40 | 41 | private EventHandler m_Completed; 42 | 43 | public event EventHandler Completed 44 | { 45 | add { m_Completed += value; } 46 | remove { m_Completed -= value; } 47 | } 48 | 49 | protected void OnCompleted(ProxyEventArgs args) 50 | { 51 | if (m_Completed == null) 52 | return; 53 | 54 | m_Completed(this, args); 55 | } 56 | 57 | protected void OnException(Exception exception) 58 | { 59 | OnCompleted(new ProxyEventArgs(exception)); 60 | } 61 | 62 | protected void OnException(string exception) 63 | { 64 | OnCompleted(new ProxyEventArgs(new Exception(exception))); 65 | } 66 | 67 | protected bool ValidateAsyncResult(SocketAsyncEventArgs e) 68 | { 69 | if (e.SocketError != SocketError.Success) 70 | { 71 | var socketException = new SocketException((int)e.SocketError); 72 | OnCompleted(new ProxyEventArgs(new Exception(socketException.Message, socketException))); 73 | return false; 74 | } 75 | 76 | return true; 77 | } 78 | 79 | protected void AsyncEventArgsCompleted(object sender, SocketAsyncEventArgs e) 80 | { 81 | if (e.LastOperation == SocketAsyncOperation.Send) 82 | ProcessSend(e); 83 | else 84 | ProcessReceive(e); 85 | } 86 | 87 | protected void StartSend(Socket socket, SocketAsyncEventArgs e) 88 | { 89 | bool raiseEvent = false; 90 | 91 | try 92 | { 93 | raiseEvent = socket.SendAsync(e); 94 | } 95 | catch (Exception exc) 96 | { 97 | OnException(new Exception(exc.Message, exc)); 98 | return; 99 | } 100 | 101 | if (!raiseEvent) 102 | { 103 | ProcessSend(e); 104 | } 105 | } 106 | 107 | protected virtual void StartReceive(Socket socket, SocketAsyncEventArgs e) 108 | { 109 | bool raiseEvent = false; 110 | 111 | try 112 | { 113 | raiseEvent = socket.ReceiveAsync(e); 114 | } 115 | catch (Exception exc) 116 | { 117 | OnException(new Exception(exc.Message, exc)); 118 | return; 119 | } 120 | 121 | if (!raiseEvent) 122 | { 123 | ProcessReceive(e); 124 | } 125 | } 126 | 127 | protected abstract void ProcessConnect(Socket socket, object targetEndPoint, SocketAsyncEventArgs e, Exception exception); 128 | 129 | protected abstract void ProcessSend(SocketAsyncEventArgs e); 130 | 131 | protected abstract void ProcessReceive(SocketAsyncEventArgs e); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Net40.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {8BCA34D7-18E8-4B33-A102-9F0A3951B742} 9 | Library 10 | Properties 11 | SuperSocket.ClientEngine 12 | SuperSocket.ClientEngine 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\net35-client\SuperSocket.ProtoBase.dll 41 | True 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.MonoDroid.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {1FECD16C-D200-4184-B2DF-9A5DE15CD3B1} 7 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Library 9 | Properties 10 | SuperSocket.ClientEngine 11 | SuperSocket.ClientEngine 12 | 512 13 | Off 14 | False 15 | v2.3 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE;AWAIT 23 | prompt 24 | 4 25 | 26 | 27 | true 28 | bin\Release\ 29 | TRACE;AWAIT 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\SuperSocket.ProtoBase.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 90 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Net45.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8BBFBE4A-B91A-4DCC-92D5-FB0436E2544F} 8 | Library 9 | Properties 10 | SuperSocket.ClientEngine 11 | SuperSocket.ClientEngine 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | TRACE;DEBUG;AWAIT 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE;AWAIT 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\net35-client\SuperSocket.ProtoBase.dll 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 92 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Net35.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {8FD00E43-2FA2-47F4-9240-B77AE3426122} 9 | Library 10 | Properties 11 | SuperSocket.ClientEngine 12 | SuperSocket.ClientEngine 13 | v3.5 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | TRACE;DEBUG;NO_SPINWAIT_CLASS 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE;NO_SPINWAIT_CLASS 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\net35-client\SuperSocket.ProtoBase.dll 41 | True 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | 93 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.Net20.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {377D2203-B53E-45B6-8593-D56F7D5B5DE8} 9 | Library 10 | Properties 11 | SuperSocket.ClientEngine 12 | SuperSocket.ClientEngine 13 | v2.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | TRACE;DEBUG;NO_SPINWAIT_CLASS 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE;NO_SPINWAIT_CLASS 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\net20\SuperSocket.ProtoBase.dll 39 | True 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | 96 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.MonoTouch.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {C3792DC0-53BF-44AF-B0FF-C6F5D3D09150} 7 | {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Library 9 | SuperSocket.ClientEngine 10 | Resources 11 | SuperSocket.ClientEngine 12 | 13 | 14 | True 15 | full 16 | False 17 | bin\Debug 18 | DEBUG;__IOS__;__MOBILE__;AWAIT 19 | prompt 20 | 4 21 | False 22 | 23 | 24 | none 25 | True 26 | bin\Release 27 | prompt 28 | 4 29 | False 30 | __IOS__;__MOBILE__;AWAIT 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\SuperSocket.ProtoBase.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 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 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.SL40.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.50727 7 | 2.0 8 | {166C087B-5874-4E5B-B9EC-1963F3FAB17A} 9 | {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine 13 | SuperSocket.ClientEngine 14 | Silverlight 15 | v5.0 16 | $(TargetFrameworkVersion) 17 | false 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 4.0 25 | 26 | 29 | 30 | v3.5 31 | 32 | 33 | true 34 | full 35 | false 36 | Bin\Debug 37 | TRACE;DEBUG;SILVERLIGHT;NO_SPINWAIT_CLASS 38 | true 39 | true 40 | prompt 41 | 4 42 | 43 | 44 | pdbonly 45 | true 46 | Bin\Release 47 | TRACE;SILVERLIGHT;NO_SPINWAIT_CLASS 48 | true 49 | true 50 | prompt 51 | 4 52 | 53 | 54 | 55 | References\BouncyCastle\SL40\BouncyCastle.Crypto.dll 56 | 57 | 58 | 59 | packages\SuperSocket.ProtoBase.1.7.0.14\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\SuperSocket.ProtoBase.dll 60 | True 61 | 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 | 110 | 111 | 118 | -------------------------------------------------------------------------------- /Core/ClientSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | using System.Threading; 7 | 8 | namespace SuperSocket.ClientEngine 9 | { 10 | public abstract class ClientSession : IClientSession, IBufferSetter 11 | { 12 | public const int DefaultReceiveBufferSize = 4096; 13 | 14 | protected Socket Client { get; set; } 15 | 16 | Socket IClientSession.Socket 17 | { 18 | get { return Client; } 19 | } 20 | 21 | #if !SILVERLIGHT 22 | public virtual EndPoint LocalEndPoint { get; set; } 23 | #endif 24 | 25 | public bool IsConnected { get; private set; } 26 | 27 | public bool NoDelay { get; set; } 28 | 29 | public ClientSession() 30 | { 31 | 32 | } 33 | 34 | public int SendingQueueSize { get; set; } 35 | 36 | public abstract void Connect(EndPoint remoteEndPoint); 37 | 38 | public abstract bool TrySend(ArraySegment segment); 39 | 40 | public abstract bool TrySend(IList> segments); 41 | 42 | public void Send(byte[] data, int offset, int length) 43 | { 44 | this.Send(new ArraySegment(data, offset, length)); 45 | } 46 | 47 | #if NO_SPINWAIT_CLASS 48 | public void Send(ArraySegment segment) 49 | { 50 | if (TrySend(segment)) 51 | return; 52 | 53 | while (true) 54 | { 55 | Thread.SpinWait(1); 56 | 57 | if (TrySend(segment)) 58 | return; 59 | } 60 | } 61 | 62 | public void Send(IList> segments) 63 | { 64 | if (TrySend(segments)) 65 | return; 66 | 67 | while (true) 68 | { 69 | Thread.SpinWait(1); 70 | 71 | if (TrySend(segments)) 72 | return; 73 | } 74 | } 75 | #else 76 | public void Send(ArraySegment segment) 77 | { 78 | if (TrySend(segment)) 79 | return; 80 | 81 | var spinWait = new SpinWait(); 82 | 83 | while (true) 84 | { 85 | spinWait.SpinOnce(); 86 | 87 | if (TrySend(segment)) 88 | return; 89 | } 90 | } 91 | 92 | public void Send(IList> segments) 93 | { 94 | if (TrySend(segments)) 95 | return; 96 | 97 | var spinWait = new SpinWait(); 98 | 99 | while (true) 100 | { 101 | spinWait.SpinOnce(); 102 | 103 | if (TrySend(segments)) 104 | return; 105 | } 106 | } 107 | #endif 108 | 109 | public abstract void Close(); 110 | 111 | private EventHandler m_Closed; 112 | 113 | public event EventHandler Closed 114 | { 115 | add { m_Closed += value; } 116 | remove { m_Closed -= value; } 117 | } 118 | 119 | protected virtual void OnClosed() 120 | { 121 | IsConnected = false; 122 | LocalEndPoint = null; 123 | 124 | var handler = m_Closed; 125 | 126 | if (handler != null) 127 | handler(this, EventArgs.Empty); 128 | } 129 | 130 | private EventHandler m_Error; 131 | 132 | public event EventHandler Error 133 | { 134 | add { m_Error += value; } 135 | remove { m_Error -= value; } 136 | } 137 | 138 | protected virtual void OnError(Exception e) 139 | { 140 | var handler = m_Error; 141 | if (handler == null) 142 | return; 143 | 144 | handler(this, new ErrorEventArgs(e)); 145 | } 146 | 147 | private EventHandler m_Connected; 148 | 149 | public event EventHandler Connected 150 | { 151 | add { m_Connected += value; } 152 | remove { m_Connected -= value; } 153 | } 154 | 155 | protected virtual void OnConnected() 156 | { 157 | var client = Client; 158 | 159 | if(client != null) 160 | { 161 | try 162 | { 163 | if(client.NoDelay != NoDelay) 164 | client.NoDelay = NoDelay; 165 | } 166 | catch 167 | { 168 | } 169 | } 170 | 171 | IsConnected = true; 172 | 173 | var handler = m_Connected; 174 | if (handler == null) 175 | return; 176 | 177 | handler(this, EventArgs.Empty); 178 | } 179 | 180 | private EventHandler m_DataReceived; 181 | 182 | public event EventHandler DataReceived 183 | { 184 | add { m_DataReceived += value; } 185 | remove { m_DataReceived -= value; } 186 | } 187 | 188 | private DataEventArgs m_DataArgs = new DataEventArgs(); 189 | 190 | protected virtual void OnDataReceived(byte[] data, int offset, int length) 191 | { 192 | var handler = m_DataReceived; 193 | if (handler == null) 194 | return; 195 | 196 | m_DataArgs.Data = data; 197 | m_DataArgs.Offset = offset; 198 | m_DataArgs.Length = length; 199 | 200 | handler(this, m_DataArgs); 201 | } 202 | 203 | public virtual int ReceiveBufferSize { get; set; } 204 | 205 | public IProxyConnector Proxy { get; set; } 206 | 207 | protected ArraySegment Buffer { get; set; } 208 | 209 | void IBufferSetter.SetBuffer(ArraySegment bufferSegment) 210 | { 211 | SetBuffer(bufferSegment); 212 | } 213 | 214 | protected virtual void SetBuffer(ArraySegment bufferSegment) 215 | { 216 | Buffer = bufferSegment; 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /Protocol/AssemblyUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Reflection; 5 | using System.IO; 6 | 7 | #if SILVERLIGHT || NETFX_CORE 8 | #else 9 | using System.Runtime.Serialization.Formatters.Binary; 10 | #endif 11 | 12 | 13 | using System.Linq; 14 | 15 | 16 | 17 | namespace SuperSocket.ClientEngine.Protocol 18 | { 19 | public static class AssemblyUtil 20 | { 21 | public static bool TryCreateInstance(string type, out T result) 22 | { 23 | Exception e; 24 | return TryCreateInstance(type, out result, out e); 25 | } 26 | 27 | public static bool TryCreateInstance(string type, out T result, out Exception e) 28 | { 29 | return TryCreateInstance(type, new object[0], out result, out e); 30 | } 31 | 32 | public static bool TryCreateInstance(string type, object[] parameters, out T result, out Exception e) 33 | { 34 | Type instanceType = null; 35 | result = default(T); 36 | 37 | if (!TryGetType(type, out instanceType, out e)) 38 | return false; 39 | 40 | try 41 | { 42 | object instance = Activator.CreateInstance(instanceType, parameters); 43 | result = (T)instance; 44 | return true; 45 | } 46 | catch (Exception exc) 47 | { 48 | e = exc; 49 | return false; 50 | } 51 | } 52 | 53 | public static bool TryGetType(string type, out Type result) 54 | { 55 | Exception e; 56 | return TryGetType(type, out result, out e); 57 | } 58 | 59 | public static bool TryGetType(string type, out Type result, out Exception e) 60 | { 61 | e = null; 62 | 63 | try 64 | { 65 | result = Type.GetType(type, true); 66 | return true; 67 | } 68 | catch (Exception exc) 69 | { 70 | e = exc; 71 | result = null; 72 | return false; 73 | } 74 | } 75 | 76 | public static IEnumerable GetImplementTypes(this Assembly assembly) 77 | { 78 | #if NETFX_CORE 79 | return assembly.GetExportedTypes().Where(t => 80 | { 81 | var typeInfo = t.GetTypeInfo(); 82 | return typeInfo.IsSubclassOf(typeof(TBaseType)) && typeInfo.IsClass && !typeInfo.IsAbstract; 83 | }); 84 | #else 85 | return assembly.GetExportedTypes().Where(t => 86 | t.IsSubclassOf(typeof(TBaseType)) && t.IsClass && !t.IsAbstract); 87 | #endif 88 | } 89 | 90 | public static IEnumerable GetImplementedObjectsByInterface(this Assembly assembly) 91 | where TBaseInterface : class 92 | { 93 | Type interfaceType = typeof(TBaseInterface); 94 | Type[] arrType = assembly.GetExportedTypes(); 95 | 96 | var result = new List(); 97 | 98 | for (int i = 0; i < arrType.Length; i++) 99 | { 100 | var currentImplementType = arrType[i]; 101 | #if NETFX_CORE 102 | if (currentImplementType.GetTypeInfo().IsAbstract) 103 | continue; 104 | #else 105 | if (currentImplementType.IsAbstract) 106 | continue; 107 | #endif 108 | 109 | var foundInterface = currentImplementType.GetInterfaces().SingleOrDefault(x => x == interfaceType); 110 | 111 | if (foundInterface != null) 112 | { 113 | result.Add(currentImplementType.GetConstructor(new Type[0]).Invoke(new object[0]) as TBaseInterface); 114 | } 115 | } 116 | 117 | return result; 118 | } 119 | 120 | #if SILVERLIGHT || NETFX_CORE 121 | #else 122 | public static T BinaryClone(this T target) 123 | { 124 | BinaryFormatter formatter = new BinaryFormatter(); 125 | using (MemoryStream ms = new MemoryStream()) 126 | { 127 | formatter.Serialize(ms, target); 128 | ms.Position = 0; 129 | return (T)formatter.Deserialize(ms); 130 | } 131 | } 132 | #endif 133 | 134 | private static object[] m_EmptyObjectArray = new object[] { }; 135 | 136 | public static void CopyPropertiesTo(this object source, object target) 137 | { 138 | PropertyInfo[] properties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); 139 | Dictionary sourcePropertiesDict = properties.ToDictionary(p => p.Name); 140 | 141 | PropertyInfo[] targetProperties = target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); 142 | for (int i = 0; i < targetProperties.Length; i++) 143 | { 144 | var p = targetProperties[i]; 145 | PropertyInfo sourceProperty; 146 | if (sourcePropertiesDict.TryGetValue(p.Name, out sourceProperty)) 147 | { 148 | if (sourceProperty.PropertyType != p.PropertyType) 149 | continue; 150 | } 151 | 152 | p.SetValue(target, sourceProperty.GetValue(source, m_EmptyObjectArray), m_EmptyObjectArray); 153 | } 154 | } 155 | 156 | public static IEnumerable GetAssembliesFromString(string assemblyDef) 157 | { 158 | string[] assemblies = assemblyDef.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); 159 | 160 | List result = new List(assemblies.Length); 161 | 162 | foreach (var a in assemblies) 163 | { 164 | #if NETFX_CORE 165 | result.Add(Assembly.Load(new AssemblyName(a))); 166 | #else 167 | result.Add(Assembly.Load(a)); 168 | #endif 169 | } 170 | 171 | return result; 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /Core/SslStreamTcpSession.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Net.Security; 7 | using System.Threading; 8 | #if NETSTANDARD 9 | using System.Threading.Tasks; 10 | #endif 11 | #if !SILVERLIGHT 12 | using System.Security.Authentication; 13 | #endif 14 | using System.Security.Cryptography.X509Certificates; 15 | 16 | namespace SuperSocket.ClientEngine 17 | { 18 | public class SslStreamTcpSession : AuthenticatedStreamTcpSession 19 | { 20 | protected override void StartAuthenticatedStream(Socket client) 21 | { 22 | #if SILVERLIGHT 23 | var sslStream = new SslStream(new NetworkStream(client)); 24 | sslStream.BeginAuthenticateAsClient(HostName, OnAuthenticated, sslStream); 25 | #else 26 | var securityOption = Security; 27 | 28 | if (securityOption == null) 29 | { 30 | throw new Exception("securityOption was not configured"); 31 | } 32 | 33 | #if NETSTANDARD 34 | 35 | AuthenticateAsClientAsync(new SslStream(new NetworkStream(client), false, ValidateRemoteCertificate), Security); 36 | 37 | #else 38 | 39 | var sslStream = new SslStream(new NetworkStream(client), false, ValidateRemoteCertificate); 40 | sslStream.BeginAuthenticateAsClient(HostName, securityOption.Certificates, securityOption.EnabledSslProtocols, false, OnAuthenticated, sslStream); 41 | 42 | #endif 43 | #endif 44 | } 45 | 46 | #if NETSTANDARD 47 | private async void AuthenticateAsClientAsync(SslStream sslStream, SecurityOption securityOption) 48 | { 49 | try 50 | { 51 | await sslStream.AuthenticateAsClientAsync(HostName, securityOption.Certificates, securityOption.EnabledSslProtocols, false); 52 | } 53 | catch(Exception e) 54 | { 55 | EnsureSocketClosed(); 56 | OnError(e); 57 | return; 58 | } 59 | 60 | OnAuthenticatedStreamConnected(sslStream); 61 | } 62 | #endif 63 | 64 | 65 | #if !NETSTANDARD 66 | private void OnAuthenticated(IAsyncResult result) 67 | { 68 | var sslStream = result.AsyncState as SslStream; 69 | 70 | if(sslStream == null) 71 | { 72 | EnsureSocketClosed(); 73 | OnError(new NullReferenceException("Ssl Stream is null OnAuthenticated")); 74 | return; 75 | } 76 | 77 | try 78 | { 79 | sslStream.EndAuthenticateAsClient(result); 80 | } 81 | catch(Exception e) 82 | { 83 | EnsureSocketClosed(); 84 | OnError(e); 85 | return; 86 | } 87 | 88 | OnAuthenticatedStreamConnected(sslStream); 89 | } 90 | #endif 91 | 92 | #if !SILVERLIGHT 93 | /// 94 | /// Validates the remote certificate. 95 | /// 96 | /// The sender. 97 | /// The certificate. 98 | /// The chain. 99 | /// The SSL policy errors. 100 | /// 101 | private bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 102 | { 103 | #if !NETSTANDARD 104 | var callback = ServicePointManager.ServerCertificateValidationCallback; 105 | 106 | if (callback != null) 107 | return callback(sender, certificate, chain, sslPolicyErrors); 108 | #endif 109 | 110 | if (sslPolicyErrors == SslPolicyErrors.None) 111 | return true; 112 | 113 | if (Security.AllowNameMismatchCertificate) 114 | { 115 | sslPolicyErrors = sslPolicyErrors & (~SslPolicyErrors.RemoteCertificateNameMismatch); 116 | } 117 | 118 | if (Security.AllowCertificateChainErrors) 119 | { 120 | sslPolicyErrors = sslPolicyErrors & (~SslPolicyErrors.RemoteCertificateChainErrors); 121 | } 122 | 123 | if (sslPolicyErrors == SslPolicyErrors.None) 124 | return true; 125 | 126 | if (!Security.AllowUnstrustedCertificate) 127 | { 128 | OnError(new Exception(sslPolicyErrors.ToString())); 129 | return false; 130 | } 131 | 132 | // not only a remote certificate error 133 | if (sslPolicyErrors != SslPolicyErrors.None && sslPolicyErrors != SslPolicyErrors.RemoteCertificateChainErrors) 134 | { 135 | OnError(new Exception(sslPolicyErrors.ToString())); 136 | return false; 137 | } 138 | 139 | if (chain != null && chain.ChainStatus != null) 140 | { 141 | foreach (X509ChainStatus status in chain.ChainStatus) 142 | { 143 | if ((certificate.Subject == certificate.Issuer) && 144 | (status.Status == X509ChainStatusFlags.UntrustedRoot)) 145 | { 146 | // Self-signed certificates with an untrusted root are valid. 147 | continue; 148 | } 149 | else 150 | { 151 | if (status.Status != X509ChainStatusFlags.NoError) 152 | { 153 | OnError(new Exception(sslPolicyErrors.ToString())); 154 | // If there are any other errors in the certificate chain, the certificate is invalid, 155 | // so the method returns false. 156 | return false; 157 | } 158 | } 159 | } 160 | } 161 | 162 | // When processing reaches this line, the only errors in the certificate chain are 163 | // untrusted root errors for self-signed certificates. These certificates are valid 164 | // for default Exchange server installations, so return true. 165 | return true; 166 | } 167 | #endif 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /SuperSocket.ClientEngine.SL50.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.50727 7 | 2.0 8 | {161B7DBF-CDE1-4C6D-B555-E190E7D6A0AC} 9 | {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 10 | Library 11 | Properties 12 | SuperSocket.ClientEngine 13 | SuperSocket.ClientEngine 14 | Silverlight 15 | v5.0 16 | $(TargetFrameworkVersion) 17 | false 18 | true 19 | true 20 | 21 | 24 | 25 | v3.5 26 | 27 | 28 | true 29 | full 30 | false 31 | Bin\Debug 32 | TRACE;DEBUG;SILVERLIGHT;NO_SPINWAIT_CLASS 33 | true 34 | true 35 | prompt 36 | 4 37 | 38 | 39 | pdbonly 40 | true 41 | Bin\Release 42 | TRACE;SILVERLIGHT;NO_SPINWAIT_CLASS 43 | true 44 | true 45 | prompt 46 | 4 47 | 48 | 49 | 50 | packages\Portable.BouncyCastle-Signed.1.7.0.2\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10\crypto.dll 51 | True 52 | 53 | 54 | 55 | 56 | $(TargetFrameworkDirectory)System.Core.dll 57 | 58 | 59 | 60 | 61 | 62 | packages\SuperSocket.ProtoBase.1.7.0.17\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\SuperSocket.ProtoBase.dll 63 | True 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 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 123 | --------------------------------------------------------------------------------