示例#1
0
        public sessionClient(int timeoutMinutes, int queueCount = 0, fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethod <session <valueType> .tcpClient> verifyMethod = null)
#endif
            : base(attribute, verifyMethod)
        {
            queue           = new fifoPriorityQueue <sessionId, valueType>();
            this.queueCount = Math.Max(queueCount <= 0 ? fastCSharp.config.http.Default.ClientSessionQueueCount : queueCount, 1);
        }
            public commandClient(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethod <commandClient> verifyMethod)
#endif
            {
                if (attribute == null)
                {
                    log.Error.Throw(log.exceptionType.Null);
                }
                client = new commandClient <commandClient>(attribute, 1024, verifyMethod ?? new verifyMethod(), this);
            }
示例#3
0
 /// <summary>
 /// 获取配置信息
 /// </summary>
 /// <param name="attribute">TCP服务器配置信息</param>
 /// <param name="serviceName">TCP调用服务名称</param>
 /// <returns>TCP调用服务器端配置信息</returns>
 public static tcpServer GetConfig(tcpServer attribute, string serviceName)
 {
     attribute = fastCSharp.config.pub.LoadConfig(attribute, serviceName);
     if (attribute.Service == null)
     {
         attribute.Service = serviceName;
     }
     return(attribute);
 }
示例#4
0
        public form(int isStart)
        {
            InitializeComponent();
            context = SynchronizationContext.Current;

            tcpServer                    = fastCSharp.code.cSharp.tcpServer.GetConfig("tcpPerformance", typeof(fastCSharp.demo.tcpPerformanceServer.performanceServer));
            ipTextBox.Text               = tcpServer.Host;
            portTextBox.Text             = (defaultPort = tcpServer.Port).toString();
            asynchronousCheckBox.Checked = tcpServer.IsClientAsynchronousReceive;

            if (isStart != 0)
            {
                start(null, null);
            }
        }
            public bool Verify(fastCSharp.net.tcp.commandLoadBalancingServer.commandClient client)
#endif
            {
#if NOJIT
                fastCSharp.net.tcp.commandLoadBalancingServer.commandClient client = (fastCSharp.net.tcp.commandLoadBalancingServer.commandClient)clientObject;
#endif
                fastCSharp.net.tcp.timeVerifyServer.input input         = new fastCSharp.net.tcp.timeVerifyServer.input();
                fastCSharp.net.tcp.commandClient          commandClient = client.TcpCommandClient;
                fastCSharp.code.cSharp.tcpServer          attribute     = commandClient.Attribute;
                string verifyString = attribute.VerifyString;
                if (verifyString == null)
                {
                    return(client.Verify(ref input).Value.Ret);
                }
                ulong markData = 0;
                if (attribute.IsMarkData)
                {
                    markData = attribute.VerifyHashCode;
                }
                input.ticks = date.UtcNow.Ticks;
                do
                {
                    input.randomPrefix = random.Default.SecureNextULongNotZero();
                    while (input.randomPrefix == markData)
                    {
                        input.randomPrefix = random.Default.SecureNextULongNotZero();
                    }
                    commandClient.ReceiveMarkData = attribute.IsMarkData ? markData ^ input.randomPrefix : 0UL;
                    commandClient.SendMarkData    = 0;
                    input.MD5(verifyString);
                    long lastTicks = input.ticks;
                    fastCSharp.net.returnValue <fastCSharp.net.tcp.timeVerifyServer.output> isVerify = client.Verify(ref input);
                    if (isVerify.Value.Ret)
                    {
                        commandClient.SendMarkData = commandClient.ReceiveMarkData;
                        return(true);
                    }
                    if (isVerify.Type != fastCSharp.net.returnValue.type.Success || input.ticks <= lastTicks)
                    {
                        return(false);
                    }
                    ++input.ticks;
                    log.Error.Add("TCP客户端验证时间失败重试", null, false);
                }while (true);
            }
示例#6
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="serviceName">TCP调用服务名称</param>
        /// <param name="type">TCP服务器类型</param>
        /// <returns>TCP调用服务器端配置信息</returns>
        public static tcpServer GetTcpCallConfig(string serviceName, Type type = null)
        {
            tcpServer attribute = new tcpServer();

            if (type != null)
            {
                tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute <tcpCall>(type, false, true);
                if (tcpCall != null)
                {
                    attribute.CopyFrom(tcpCall);
                }
            }
            attribute = fastCSharp.config.pub.LoadConfig(attribute, serviceName);
            if (attribute.Service == null)
            {
                attribute.Service = serviceName;
            }
            return(attribute);
        }
示例#7
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="serviceName">TCP调用服务名称</param>
        /// <param name="type">TCP服务器类型</param>
        /// <returns>TCP调用服务器端配置信息</returns>
        public static tcpServer GetConfig(string serviceName, Type type = null)
        {
            tcpServer attribute = null;

            if (type != null)
            {
                attribute = fastCSharp.code.typeAttribute.GetAttribute <tcpServer>(type, false, true);
                if (attribute != null)
                {
                    attribute = attribute.Clone();
                }
            }
            attribute = fastCSharp.config.pub.LoadConfig(attribute ?? new tcpServer(), serviceName);
            if (attribute.Service == null)
            {
                attribute.Service = serviceName;
            }
            return(attribute);
        }
示例#8
0
 /// <summary>
 /// 获取TCP调用泛型函数集合
 /// </summary>
 /// <param name="type">目标类型</param>
 /// <returns>TCP调用泛型函数集合</returns>
 public static Dictionary <genericMethod, MethodInfo> GetGenericMethods(Type type)
 {
     if (type != null)
     {
         tcpServer tcpServer = fastCSharp.code.typeAttribute.GetAttribute <tcpServer>(type, false, false);//cSharp.Default.IsInheritAttribute
         if (tcpServer != null && tcpServer.IsSetup)
         {
             Dictionary <genericMethod, MethodInfo> values = dictionary.Create <genericMethod, MethodInfo>();
             code.methodInfo[] methods = code.methodInfo.GetMethods <tcpServer>(type, tcpServer.MemberFilter, false, tcpServer.IsAttribute, tcpServer.IsBaseTypeAttribute, tcpServer.IsInheritAttribute);
             if (type.IsGenericType)
             {
                 code.methodInfo[] definitionMethods = code.methodInfo.GetMethods <tcpServer>(type.GetGenericTypeDefinition(), tcpServer.MemberFilter, false, tcpServer.IsAttribute, tcpServer.IsBaseTypeAttribute, tcpServer.IsInheritAttribute);
                 int index = 0;
                 foreach (code.methodInfo method in methods)
                 {
                     if (method.Method.IsGenericMethod)
                     {
                         values.Add(new genericMethod(definitionMethods[index].Method), method.Method);
                     }
                     ++index;
                 }
             }
             else
             {
                 foreach (code.methodInfo method in methods)
                 {
                     if (method.Method.IsGenericMethod)
                     {
                         values.Add(new genericMethod(method.Method), method.Method);
                     }
                 }
             }
             return(values);
         }
     }
     return(null);
 }
        /// <summary>
        /// TCP调用负载均衡服务端
        /// </summary>
        /// <param name="attribute">TCP调用服务器端配置信息</param>
        /// <param name="verifyMethod">验证函数接口</param>
#if NOJIT
        protected commandLoadBalancingServer(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethodAsObject verifyMethod)
        protected commandLoadBalancingServer(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethod <clientType> verifyMethod, fastCSharp.code.cSharp.tcpBase.ITcpClientVerify verify)
#endif
        {
        }
            /// <summary>
            /// TCP调用客户端
            /// </summary>
            /// <param name="attribute">TCP调用服务器端配置信息</param>
            /// <param name="verifyMethod">TCP验证方法</param>
#if NOJIT
            public commandClient(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethodAsObject verifyMethod)
示例#12
0
        /// <summary>
        /// TCP调用客户端
        /// </summary>
        /// <param name="timeoutMinutes">超时分钟数</param>
        /// <param name="queueCount">客户端缓存队列最大数量</param>
        /// <param name="attribute">TCP调用服务器端配置信息</param>
        /// <param name="verifyMethod">TCP验证方法</param>
#if NOJIT
        public sessionClient(int timeoutMinutes, int queueCount = 0, fastCSharp.code.cSharp.tcpServer attribute = null, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethodAsObject verifyMethod = null)
 /// <summary>
 /// 创建TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <returns>TCP调用客户端</returns>
 protected abstract clientType _createClient_(fastCSharp.code.cSharp.tcpServer attribute);
示例#14
0
        ///// <summary>
        ///// 客户端队列初始容器大小(2^n)
        ///// </summary>
        //public byte AcceptQueueSize = 4;
#endif
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="type">TCP服务器类型</param>
        /// <returns>TCP调用服务器端配置信息</returns>
        public static tcpServer GetConfig(Type type)
        {
            tcpServer attribute = fastCSharp.code.typeAttribute.GetAttribute <tcpServer>(type, false, true);

            return(attribute != null?fastCSharp.config.pub.LoadConfig(attribute.Clone(), attribute.Service) : null);
        }
        protected commandLoadBalancingServer(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerifyMethod <clientType> verifyMethod)
#endif
        {
            this.attribute = attribute;
            _verifyMethod_ = verifyMethod;
        }
 /// <summary>
 /// TCP调用负载均衡服务端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 /// <param name="verify">验证接口</param>
 protected commandLoadBalancingServer(fastCSharp.code.cSharp.tcpServer attribute, fastCSharp.code.cSharp.tcpBase.ITcpClientVerify verify)
 {
     this.attribute = attribute;
     _verify_       = verify;
 }
 /// <summary>
 /// 添加TCP调用服务端
 /// </summary>
 /// <param name="host">TCP服务端口信息</param>
 /// <returns>是否添加成功</returns>
 private bool newServer(ref host host)
 {
     if (isDisposed == 0)
     {
         try
         {
             fastCSharp.code.cSharp.tcpServer attribute = this.attribute.Clone();
             attribute.IsLoadBalancing = true;
             attribute.Host            = host.Host;
             attribute.Port            = host.Port;
             clientType client = _createClient_(attribute);
             if (client != null)
             {
                 Monitor.Enter(clientLock);
                 for (int index = 0; index != currentCount; ++index)
                 {
                     keyValue <clientType, int> removeClient = this.clients[index].ReSet(ref host, client);
                     if (removeClient.Key != null)
                     {
                         callCount -= removeClient.Value;
                         Monitor.Exit(clientLock);
                         pub.Dispose(ref removeClient.Key);
                         return(true);
                     }
                 }
                 if (freeIndexs.length == 0)
                 {
                     if (currentCount == this.clients.Length)
                     {
                         try
                         {
                             clientHost[] clients = new clientHost[currentCount << 1];
                             this.clients.CopyTo(clients, 0);
                             clients[currentCount].Set(ref host, client, currentCount);
                             this.clients = clients;
                             ++currentCount;
                             client = null;
                         }
                         finally
                         {
                             Monitor.Exit(clientLock);
                             pub.Dispose(ref client);
                         }
                     }
                     else
                     {
                         clients[currentCount].Set(ref host, client, currentCount);
                         ++currentCount;
                         Monitor.Exit(clientLock);
                     }
                 }
                 else
                 {
                     clients[freeIndexs.UnsafePop()].Set(ref host, client);
                     Monitor.Exit(clientLock);
                 }
                 return(true);
             }
         }
         catch (Exception error)
         {
             log.Error.Add(error, null, false);
         }
     }
     return(false);
 }
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP调用服务器端配置信息</param>
 public commandClient(fastCSharp.code.cSharp.tcpServer attribute) : this(attribute, null)
 {
 }
示例#19
0
        internal static bool TestCase()
        {
            using (tcpHttp.tcpServer server = new tcpHttp.tcpServer())
            {
                if (server.Start())
                {
                    fastCSharp.code.cSharp.tcpServer tcpServer = fastCSharp.code.typeAttribute.GetAttribute <fastCSharp.code.cSharp.tcpServer>(typeof(tcpHttp), false, false);
                    System.Text.Encoding             encoding  = System.Text.Encoding.UTF8;
                    string url = "http://" + tcpServer.Host + ":" + tcpServer.Port.toString() + "/";
                    using (tcpHttp.tcpClient client = new tcpHttp.tcpClient())
                        using (fastCSharp.net.webClient webClient = new fastCSharp.net.webClient())
                        {
                            incValue = 0;
                            //TCP调用
                            client.Inc();
                            if (incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+JSON调用
                            incValue            = 0;
                            webClient.KeepAlive = false;
                            if (webClient.UploadData(url + "Inc", new byte[0]).deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+POST调用
                            incValue = 0;
                            if (webClient.UploadValues(url + "Inc", new NameValueCollection()).deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+GET调用
                            incValue = 0;
                            if (webClient.DownloadData(url + "Inc").deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }

                            client.Set(3);
                            if (incValue != 3)
                            {
                                return(false);
                            }
                            incValue = 0;
                            if (webClient.UploadData(url + "Set", encoding.GetBytes(3.ToJson())).deSerialize() != web.ajax.Object || incValue != 3)
                            {
                                return(false);
                            }
                            //incValue = 0;
                            //if (webClient.UploadValues(url + "Set", fastCSharp.emit.formGetter<.form.Get(new { a = 3 })).deSerialize() != web.ajax.Object || incValue != 3) return false;
                            //incValue = 0;
                            //if (webClient.DownloadData(url + "Set?" + urlQuery.query.Get(new { a = 3 }, encoding)).deSerialize() != web.ajax.Object || incValue != 3) return false;

                            client.Add(2, 3);
                            if (incValue != 5)
                            {
                                return(false);
                            }
                            incValue = 0;
                            if (webClient.UploadData(url + "Add", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 2, b = 3 }))).deSerialize() != web.ajax.Object || incValue != 5)
                            {
                                return(false);
                            }
                            //incValue = 0;
                            //if (webClient.UploadValues(url + "Add", urlQuery.form.Get(new { a = 2, b = 3 })).deSerialize() != web.ajax.Object || incValue != 5) return false;
                            //incValue = 0;
                            //if (webClient.DownloadData(url + "Add?" + urlQuery.query.Get(new { a = 2, b = 3 }, encoding)).deSerialize() != web.ajax.Object || incValue != 5) return false;

                            if (client.inc().Value != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "inc", new byte[0]).deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadValues(url + "inc", new NameValueCollection()).deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.DownloadData(url + "inc").deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }

                            if (client.inc(8).Value != 9)
                            {
                                return(false);
                            }
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "inc1", encoding.GetBytes(8.ToJson())).deSerialize()) != 9)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "inc1", urlQuery.form.Get(new { a = 8 })).deSerialize() != "9") return false;
                            //if (webClient.DownloadData(url + "inc1?" + urlQuery.query.Get(new { a = 8 }, encoding)).deSerialize() != "9") return false;

                            if (client.add(10, 13).Value != 23)
                            {
                                return(false);
                            }
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "add", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 10, b = 13 }))).deSerialize()) != 23)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "add", urlQuery.form.Get(new { a = 10, b = 13 })).deSerialize() != "23") return false;
                            //if (webClient.DownloadData(url + "add?" + urlQuery.query.Get(new { a = 10, b = 13 }, encoding)).deSerialize() != "23") return false;

                            int a;
                            incValue = 15;
                            if (client.inc(out a).Value != 16 || a != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            outReturn value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "inc2", new byte[0]).deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            value    = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadValues(url + "inc2", new NameValueCollection()).deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            value    = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.DownloadData(url + "inc2").deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }

                            if (client.inc(20, out a).Value != 21 || a != 20)
                            {
                                return(false);
                            }
                            value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "inc3", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 20 }))).deSerialize());
                            if (value.Return != 21 || value.outValue != 20)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "inc3", urlQuery.form.Get(new { a = 20 })).deSerialize() != @"{""b"":20,""_Return_"":21}") return false;
                            //if (webClient.DownloadData(url + "inc3?" + urlQuery.query.Get(new { a = 20 }, encoding)).deSerialize() != @"{""b"":20,""_Return_"":21}") return false;

                            if (client.add(30, 33, out a).Value != 63 || a != 33)
                            {
                                return(false);
                            }
                            value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "add1", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 30, b = 33 }))).deSerialize());
                            if (value.Return != 63 || value.outValue != 33)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "add1", urlQuery.form.Get(new { a = 30, b = 33 })).deSerialize() != @"{""c"":33,""_Return_"":63}") return false;
                            //if (webClient.DownloadData(url + "add1?" + urlQuery.query.Get(new { a = 30, b = 33 }, encoding)).deSerialize() != @"{""c"":33,""_Return_"":63}") return false;

                            if (webClient.UploadData(url + "setCookie", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { name = "a", value = "b" }))).deSerialize() != web.ajax.Object)
                            {
                                return(false);
                            }
                            if (webClient.ResponseHeaders["Set-Cookie"] != "a=b")
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "setCookie", urlQuery.form.Get(new { name = "c", value = "d" })).deSerialize() != web.ajax.Object) return false;
                            //if (webClient.ResponseHeaders["Set-Cookie"] != "c=d") return false;
                            //if (webClient.DownloadData(url + "setCookie?" + urlQuery.query.Get(new { name = "e", value = "f" }, encoding)).deSerialize() != web.ajax.Object) return false;
                            //if (webClient.ResponseHeaders["Set-Cookie"] != "e=f") return false;

                            if (!fastCSharp.emit.jsonParser.Parse <bool>(webClient.UploadData(url + "setSession", encoding.GetBytes("b".ToJson())).deSerialize()))
                            {
                                return(false);
                            }
                            webClient.Cookies.SetCookies(new Uri(url), webClient.ResponseHeaders["Set-Cookie"].Split(';')[0]);
                            if (fastCSharp.emit.jsonParser.Parse <string>(webClient.UploadData(url + "getSession", new byte[0]).deSerialize()) != "b")
                            {
                                return(false);
                            }

                            //if (webClient.UploadValues(url + "setSession", urlQuery.form.Get(new { value = "d" })).deSerialize() != @"1") return false;
                            //if (webClient.UploadValues(url + "getSession", new NameValueCollection()).deSerialize() != @"""d""") return false;

                            //if (webClient.DownloadData(url + "setSession?" + urlQuery.query.Get(new { value = "f" }, encoding)).deSerialize() != @"1") return false;
                            //if (webClient.DownloadData(url + "getSession").deSerialize() != @"""f""") return false;
#if APP
#else
                            //HTTP文件上传
#if MONO
                            FileInfo fileInfo = new FileInfo((@"..\..\Program.cs").pathSeparator());
#else
                            FileInfo fileInfo = new FileInfo((@"..\..\tcpHttp.cs").pathSeparator());
#endif
                            if (fastCSharp.emit.jsonParser.Parse <long>(webClient.UploadFile(url + "httpUpload", fileInfo.FullName).deSerialize()) != fileInfo.Length)
                            {
                                return(false);
                            }
#endif
                            return(true);
                        }
                }
            }
            return(false);
        }