Browse Source

tcp连接工具调整,delegate改为action

yuzhengyang 5 years ago
parent
commit
c597e7bec3

+ 2 - 1
Azylee.Utils/Azylee.YeahWeb/Azylee.YeahWeb.csproj

@@ -66,7 +66,8 @@
     <Compile Include="HttpUtils\Models\UserAgents.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="SocketUtils\SocketTool.cs" />
-    <Compile Include="SocketUtils\TcpUtils\TcpClientDictionary.cs" />
+    <Compile Include="SocketUtils\TcpUtils\TcpClientInfo.cs" />
+    <Compile Include="SocketUtils\TcpUtils\TcpClientManager.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcppClient.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcpDataConverter.cs" />
     <Compile Include="SocketUtils\TcpUtils\TcpDataModel.cs" />

+ 0 - 14
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpClientDictionary.cs

@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Text;
-
-namespace Azylee.YeahWeb.SocketUtils.TcpUtils
-{
-    public class TcpClientDictionary
-    {
-        public string Host { get; set; }
-        public TcpClient Client { get; set; }
-    }
-}

+ 52 - 0
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpClientInfo.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+
+namespace Azylee.YeahWeb.SocketUtils.TcpUtils
+{
+    public class TcpClientInfo
+    {
+        /// <summary>
+        /// 唯一编号
+        /// </summary>
+        public int Number { get; set; }
+        /// <summary>
+        /// 客户端远程终结点(IP:Port)
+        /// </summary>
+        public string Host { get; set; }
+        /// <summary>
+        /// 连接时间
+        /// </summary>
+        public DateTime ConnectTime { get; set; }
+        /// <summary>
+        /// 是否连接
+        /// </summary>
+        public bool IsConnect { get; set; }
+        /// <summary>
+        /// 连接密钥
+        /// </summary>
+        public string  ConnectKey { get; set; }
+        /// <summary>
+        /// 上行流量总计
+        /// </summary>
+        public long UploadFlowCount { get; set; }
+        /// <summary>
+        /// 最后发送数据时间
+        /// </summary>
+        public DateTime LastUploadTime { get; set; }
+        /// <summary>
+        /// 下行流量总计
+        /// </summary>
+        public long DownloadFlowCount { get; set; }
+        /// <summary>
+        /// 最后接受数据时间
+        /// </summary>
+        public DateTime LastDownloadTime { get; set; }
+        /// <summary>
+        /// 客户端对象
+        /// </summary>
+        public TcpClient Client { get; set; }
+    }
+}

+ 193 - 0
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpClientManager.cs

@@ -0,0 +1,193 @@
+using Azylee.Core.DataUtils.CollectionUtils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+
+namespace Azylee.YeahWeb.SocketUtils.TcpUtils
+{
+    public class TcpClientManager
+    {
+        private int HostNumber { get; set; }
+        private List<TcpClientInfo> TcpClientList { get; set; }
+        /// <summary>
+        /// 构造方法(初始化标号起始标记6位,初始化客户端列表)
+        /// </summary>
+        public TcpClientManager()
+        {
+            HostNumber = 100000;
+            TcpClientList = new List<TcpClientInfo>();
+        }
+
+
+        #region 统计项
+        /// <summary>
+        /// 当前连接客户端总数
+        /// </summary>
+        /// <returns></returns>
+        public int CountClient()
+        {
+            return TcpClientList.Count();
+        }
+        #endregion
+
+        #region 判定项
+        public bool IsExistByNumber(int number)
+        {
+            if (Ls.Ok(TcpClientList))
+            {
+                return TcpClientList.Any(x => x.Number == number);
+            }
+            return false;
+        }
+        public bool IsExistByHost(string host)
+        {
+            if (Ls.Ok(TcpClientList))
+            {
+                return TcpClientList.Any(x => x.Host == host);
+            }
+            return false;
+        }
+        public bool IsConnectKey(string host, string key)
+        {
+            var item = GetInfoByHost(host);
+            if (item != null) return item.ConnectKey == key;
+            return false;
+        }
+        #endregion
+
+
+        #region 查询项
+        public List<TcpClientInfo> GetAll()
+        {
+            return TcpClientList;
+        }
+        public TcpClientInfo GetInfoByNumber(int number)
+        {
+            if (IsExistByNumber(number))
+            {
+                return TcpClientList.FirstOrDefault(x => x.Number == number);
+            }
+            return null;
+        }
+        public TcpClientInfo GetInfoByHost(string host)
+        {
+            TcpClientInfo client = null;
+            try
+            {
+                if (IsExistByHost(host))
+                {
+                    client = TcpClientList.FirstOrDefault(x => x.Host == host);
+                }
+            }
+            catch { }
+            return client;
+        }
+        #endregion
+
+        #region 添加项
+        /// <summary>
+        /// 添加或更新到客户端列表
+        /// </summary>
+        public int AddOrUpdate(string host, TcpClient client)
+        {
+            try
+            {
+                HostNumber++;
+                var item = TcpClientList.FirstOrDefault(x => x.Host == host);
+                if (item == null)
+                {
+                    var model = new TcpClientInfo()
+                    {
+                        Number = HostNumber,
+                        Host = host,
+                        Client = client,
+                        IsConnect = true,
+                        ConnectTime = DateTime.Now
+                    };
+                    TcpClientList.Add(model);
+                    return model.Number;
+                }
+                else
+                {
+                    item.Client = client;
+                }
+            }
+            catch { }
+            return 0;
+        }
+        #endregion
+
+        #region 更新项
+        public bool UpdateConnectKey(string host, string s)
+        {
+            if (IsExistByHost(host))
+            {
+                for (var i = 0; i < TcpClientList.Count; i++)
+                {
+                    if (TcpClientList[i].Host == host)
+                    {
+                        TcpClientList[i].ConnectKey = s;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+        public bool UpdateUploadFlowCount(string host, long flow)
+        {
+            if (IsExistByHost(host))
+            {
+                for (var i = 0; i < TcpClientList.Count; i++)
+                {
+                    if (TcpClientList[i].Host == host)
+                    {
+                        TcpClientList[i].UploadFlowCount += flow;
+                        TcpClientList[i].LastUploadTime = DateTime.Now;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+        public bool UpdateDownloadFlowCount(string host, long flow)
+        {
+            if (IsExistByHost(host))
+            {
+                for (var i = 0; i < TcpClientList.Count; i++)
+                {
+                    if (TcpClientList[i].Host == host)
+                    {
+                        TcpClientList[i].DownloadFlowCount += flow;
+                        TcpClientList[i].LastDownloadTime = DateTime.Now;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+        #endregion
+
+        #region 删除项
+        public int RemoveByNumber(int number)
+        {
+            try
+            {
+                return TcpClientList.RemoveAll(x => x.Number == number);
+            }
+            catch { }
+            return 0;
+        }
+        public int RemoveByHost(string host)
+        {
+            try
+            {
+                return TcpClientList.RemoveAll(x => x.Host == host);
+            }
+            catch { }
+            return 0;
+        }
+        #endregion
+    }
+}

+ 1 - 0
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcpDelegate.cs

@@ -8,6 +8,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
     /// <summary>
     /// Tcp 工具 委托声明
     /// </summary>
+    [Obsolete]
     public class TcpDelegate
     {
         /// <summary>

+ 19 - 19
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcppClient.cs

@@ -18,28 +18,26 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         private TcpClient Client = null;
         private NetworkStream networkStream = null;
 
-        TcpDelegate.ReceiveMessage ReceiveMessage;
-        TcpDelegate.OnConnect OnConnect;
-        TcpDelegate.OnDisconnect OnDisconnect;
-
-        //public TcpDataConverter.Message ReceiveMessage;
+        Action OnConnectAction = null;
+        Action OnDisconnectAction = null;
+        Action<TcpDataModel> OnReceiveAction = null;
 
         /// <summary>
         /// 构造函数
         /// </summary>
         /// <param name="ip"></param>
         /// <param name="port"></param>
-        public TcppClient(string ip, int port,
-            TcpDelegate.ReceiveMessage receive,
-              TcpDelegate.OnConnect connect,
-               TcpDelegate.OnDisconnect disconnect)
+        /// <param name="onConnect">连接动作</param>
+        /// <param name="onDisconnect">断开动作</param>
+        /// <param name="onReceive">接收消息</param>
+        public TcppClient(string ip, int port, Action onConnect, Action onDisconnect, Action<TcpDataModel> onReceive)
         {
             this._IP = ip;
             this._Port = port;
 
-            ReceiveMessage += receive;
-            OnConnect += connect;
-            OnDisconnect += disconnect;
+            OnConnectAction = onConnect;
+            OnDisconnectAction = onDisconnect;
+            OnReceiveAction = onReceive;
         }
 
         #region 连接和关闭连接
@@ -114,16 +112,18 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                 this.Client = (TcpClient)state.AsyncState;
                 this.Client.EndConnect(state);
 
-                string host = this.Client.Client.RemoteEndPoint.ToString();
-                ConnectTask(host, this.Client);
+                // c# 系统检测到在一个调用中尝试使用指针参数时的无效指针地址 怎么解决
+                // 用管理身份运行cmd,执行 netsh winsock reset 重启问题解决
+                //string host = this.Client.Client.RemoteEndPoint.ToString();
+                ConnectTask(Client);
             }
-            catch { }
+            catch (Exception ex) { }
         }
-        private void ConnectTask(string host, TcpClient client)
+        private void ConnectTask(TcpClient client)
         {
             Task.Factory.StartNew(() =>
             {
-                OnConnect?.Invoke(host);//委托:已连接
+                OnConnectAction?.Invoke();//委托:已连接
                 while (client.Connected)
                 {
                     try
@@ -138,7 +138,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                             }
                             else
                             {
-                                ReceiveMessage(host, model);//委托:接收消息
+                                OnReceiveAction?.Invoke(model);//委托:接收消息
                             }
                         }
                     }
@@ -146,7 +146,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                     //Sleep.S(1);
                 }
                 client.Close();
-                OnDisconnect?.Invoke(host);//委托:断开连接
+                OnDisconnectAction?.Invoke();//委托:断开连接
             });
             //lstn.BeginAcceptTcpClient(new AsyncCallback(acceptCallback), lstn);
         }

+ 22 - 80
Azylee.Utils/Azylee.YeahWeb/SocketUtils/TcpUtils/TcppServer.cs

@@ -20,28 +20,25 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         private List<byte> ReceiveByte = new List<byte>();
         private int _Port = 52801;
         TcpListener Listener = null;
-        TcpDelegate.ReceiveMessage ReceiveMessage;
-        TcpDelegate.OnConnect OnConnect;
-        TcpDelegate.OnDisconnect OnDisconnect;
-        List<TcpClientDictionary> Clients = new List<TcpClientDictionary>();
+        Action<TcpClientInfo> OnConnectAction = null;
+        Action<TcpClientInfo> OnDisconnectAction = null;
+        Action<TcpClientInfo, TcpDataModel> OnReceiveAction = null;
+        public TcpClientManager TcpClientManager = new TcpClientManager();
 
         /// <summary>
         /// 构造函数
         /// </summary>
         /// <param name="port">端口号</param>
-        /// <param name="receive">接收消息</param>
-        /// <param name="connect">连接动作</param>
-        /// <param name="disconnect">断开动作</param>
-        public TcppServer(int port,
-            TcpDelegate.ReceiveMessage receive,
-              TcpDelegate.OnConnect connect,
-               TcpDelegate.OnDisconnect disconnect)
+        /// <param name="onConnect">连接动作</param>
+        /// <param name="onDisconnect">断开动作</param>
+        /// <param name="onReceive">接收消息</param>
+        public TcppServer(int port, Action<TcpClientInfo> onConnect, Action<TcpClientInfo> onDisconnect, Action<TcpClientInfo, TcpDataModel> onReceive)
         {
             _Port = port;
 
-            ReceiveMessage += receive;
-            OnConnect += connect;
-            OnDisconnect += disconnect;
+            OnConnectAction = onConnect;
+            OnDisconnectAction = onDisconnect;
+            OnReceiveAction = onReceive;
         }
 
         #region 启动和停止服务
@@ -59,12 +56,11 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         /// </summary>
         public void Stop()
         {
-            foreach (var client in Clients)
+            foreach (var client in TcpClientManager.GetAll())
             {
                 client?.Client?.Close();
             }
-            Clients.Clear();
-            this.Listener?.Stop();
+            Listener?.Stop();
         }
         #endregion
 
@@ -76,11 +72,12 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         /// <param name="model">数据模型</param>
         public void Write(string host, TcpDataModel model)
         {
-            var dictionary = Clients_Get(host);
+            var dictionary = TcpClientManager.GetInfoByHost(host);
             if (dictionary != null && dictionary.Client != null)
             {
                 if (dictionary.Client.Connected)
                 {
+                    TcpClientManager.UpdateUploadFlowCount(host, model.Data.Length);
                     bool flag = TcpStreamHelper.Write(dictionary.Client, model);
                 }
             }
@@ -114,7 +111,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                 TcpClient client = lstn.EndAcceptTcpClient(state);
                 string host = client.Client.RemoteEndPoint.ToString();
 
-                Clients_Add_Update(host, client);
+                TcpClientManager.AddOrUpdate(host, client);
                 ConnectTask(host, client);
 
                 lstn.BeginAcceptTcpClient(new AsyncCallback(acceptCallback), lstn);
@@ -123,6 +120,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
         }
         private void ConnectTask(string host, TcpClient client)
         {
+            TcpClientInfo clientInfo = TcpClientManager.GetInfoByHost(host);
             DateTime HeartbeatTime = DateTime.Now;
 
             //发送心跳
@@ -142,7 +140,7 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
             //接收消息
             Task.Factory.StartNew(() =>
             {
-                OnConnect?.Invoke(host);//委托:已连接
+                OnConnectAction?.Invoke(clientInfo);//委托:已连接
                 while (client.Connected)
                 {
                     try
@@ -157,7 +155,8 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                             }
                             else
                             {
-                                ReceiveMessage(host, model);//委托:接收消息
+                                TcpClientManager.UpdateDownloadFlowCount(host, model.Data.Length);
+                                OnReceiveAction(clientInfo, model);//委托:接收消息
                             }
                         }
                     }
@@ -165,67 +164,10 @@ namespace Azylee.YeahWeb.SocketUtils.TcpUtils
                     //Sleep.S(1);
                 }
                 client.Close();
-                Clients_Del(host);
-                OnDisconnect?.Invoke(host);//委托:断开连接
+                TcpClientManager.RemoveByHost(host);
+                OnDisconnectAction?.Invoke(clientInfo);//委托:断开连接
             });
         }
         #endregion
-
-        #region 连接的客户端列表维护
-        /// <summary>
-        /// 获取连接的客户端
-        /// </summary>
-        /// <returns></returns>
-        private TcpClientDictionary Clients_Get(string host)
-        {
-            TcpClientDictionary client = null;
-            try
-            {
-                client = Clients.FirstOrDefault(x => x.Host == host);
-            }
-            catch { }
-            return client;
-        }
-        /// <summary>
-        /// 添加或更新到客户端列表
-        /// </summary>
-        private void Clients_Add_Update(string host, TcpClient client)
-        {
-            try
-            {
-                var item = Clients.FirstOrDefault(x => x.Host == host);
-                if (item == null)
-                {
-                    Clients.Add(new TcpClientDictionary() { Host = host, Client = client });
-                }
-                else
-                {
-                    item.Client = client;
-                }
-            }
-            catch { }
-        }
-        /// <summary>
-        /// 从客户端列表中删除
-        /// </summary>
-        private int Clients_Del(string host)
-        {
-            int count = 0;
-            try
-            {
-                count = Clients.RemoveAll(x => x.Host == host);
-            }
-            catch { }
-            return count;
-        }
-        /// <summary>
-        /// 当前连接客户端总数
-        /// </summary>
-        /// <returns></returns>
-        public int ClientsCount()
-        {
-            return Clients.Count();
-        }
-        #endregion
     }
 }

+ 26 - 34
Azylee.Utils/Tests/Test.TcpClientApp/Properties/Resources.Designer.cs

@@ -1,69 +1,61 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     此代码由工具生成。
-//     运行时版本: 4.0.30319.42000
+//     运行时版本:4.0.30319.42000
 //
-//     对此文件的更改可能导致不正确的行为,如果
-//     重新生成代码,则所做更改将丢失。
+//     对此文件的更改可能导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Test.TcpClientApp.Properties
-{
-
-
+namespace Test.TcpClientApp.Properties {
+    using System;
+    
+    
     /// <summary>
-    ///   强类型资源类,用于查找本地化字符串等。
+    ///   一个强类型资源类,用于查找本地化字符串等。
     /// </summary>
     // 此类是由 StronglyTypedResourceBuilder
     // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
-    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
     // (以 /str 作为命令选项),或重新生成 VS 项目。
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    internal class Resources
-    {
-
+    internal class Resources {
+        
         private static global::System.Resources.ResourceManager resourceMan;
-
+        
         private static global::System.Globalization.CultureInfo resourceCulture;
-
+        
         [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
-        internal Resources()
-        {
+        internal Resources() {
         }
-
+        
         /// <summary>
-        ///   返回此类使用的缓存 ResourceManager 实例。
+        ///   返回此类使用的缓存 ResourceManager 实例。
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Resources.ResourceManager ResourceManager
-        {
-            get
-            {
-                if ((resourceMan == null))
-                {
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.TcpClientApp.Properties.Resources", typeof(Resources).Assembly);
                     resourceMan = temp;
                 }
                 return resourceMan;
             }
         }
-
+        
         /// <summary>
-        ///   覆盖当前线程的 CurrentUICulture 属性
-        ///   使用此强类型的资源类的资源查找
+        ///   重写当前线程的 CurrentUICulture 属性
+        ///   重写当前线程的 CurrentUICulture 属性
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Globalization.CultureInfo Culture
-        {
-            get
-            {
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
                 return resourceCulture;
             }
-            set
-            {
+            set {
                 resourceCulture = value;
             }
         }

+ 13 - 17
Azylee.Utils/Tests/Test.TcpClientApp/Properties/Settings.Designer.cs

@@ -1,28 +1,24 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
-//     This code was generated by a tool.
-//     Runtime Version:4.0.30319.42000
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
 //
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace Test.TcpClientApp.Properties
-{
-
-
+namespace Test.TcpClientApp.Properties {
+    
+    
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
-    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
-    {
-
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
         private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
-        public static Settings Default
-        {
-            get
-            {
+        
+        public static Settings Default {
+            get {
                 return defaultInstance;
             }
         }

+ 6 - 1
Azylee.Utils/Tests/Test.TcpClientApp/Test.TcpClientApp.csproj

@@ -8,8 +8,9 @@
     <OutputType>WinExe</OutputType>
     <RootNamespace>Test.TcpClientApp</RootNamespace>
     <AssemblyName>Test.TcpClientApp</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -20,6 +21,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -29,6 +31,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -62,7 +65,9 @@
     <Compile Include="Properties\Resources.Designer.cs">
       <AutoGen>True</AutoGen>
       <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
     </Compile>
+    <None Include="app.config" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>

+ 3 - 0
Azylee.Utils/Tests/Test.TcpClientApp/app.config

@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>