コード例 #1
0
        protected override void Free(bool canAccessFinalizable)
        {
            FSocketConnection   = null;
            FSocketClientEvents = null;
            FCryptClientEvents  = null;
            FConnectedSync      = null;
            FLastException      = null;

            if (FReceivedQueue != null)
            {
                FReceivedQueue.Clear();
                FReceivedQueue = null;
            }

            if (FSocketClient != null)
            {
                FSocketClient.Stop();
                FSocketClient.Dispose();
                FSocketClient = null;
            }

            if (FExceptionEvent != null)
            {
                FExceptionEvent.Close();
                FExceptionEvent = null;
            }

            if (FConnectEvent != null)
            {
                FConnectEvent.Close();
                FConnectEvent = null;
            }

            if (FSentEvent != null)
            {
                FSentEvent.Close();
                FSentEvent = null;
            }

            if (FReceivedEvent != null)
            {
                FReceivedEvent.Close();
                FReceivedEvent = null;
            }

            if (FDisconnectEvent != null)
            {
                FDisconnectEvent.Close();
                FDisconnectEvent = null;
            }

            base.Free(canAccessFinalizable);
        }
コード例 #2
0
        public void Connect()
        {
            if (!Disposed)
            {
                FLastException = null;

                if (!Connected)
                {
                    FConnectEvent.Reset();
                    FExceptionEvent.Reset();
                    FDisconnectEvent.Reset();

                    FSocketClient = new SocketClient(CallbackThreadType.ctWorkerThread, FSocketClientEvents, FDelimiterType, FDelimiter, FSocketBufferSize, FMessageBufferSize);

                    SocketConnector connector = FSocketClient.AddConnector("SocketClientSync", FRemoteEndPoint);

                    connector.EncryptType     = FEncryptType;
                    connector.CompressionType = FCompressionType;
                    connector.CryptoService   = FCryptClientEvents;
                    connector.ProxyInfo       = FProxyInfo;

                    WaitHandle[] wait = new WaitHandle[] { FConnectEvent, FExceptionEvent };

                    FSocketClient.Start();

                    int signal = WaitHandle.WaitAny(wait, FConnectTimeout, false);

                    switch (signal)
                    {
                    case 0:

                        //----- Connect!
                        FLastException = null;
                        Connected      = true;

                        break;

                    case 1:

                        //----- Exception!
                        Connected         = false;
                        FSocketConnection = null;

                        FSocketClient.Stop();
                        FSocketClient.Dispose();
                        FSocketClient = null;

                        break;

                    default:

                        //----- TimeOut!
                        FLastException = new TimeoutException("Connect timeout.");

                        Connected         = false;
                        FSocketConnection = null;

                        FSocketClient.Stop();
                        FSocketClient.Dispose();
                        FSocketClient = null;

                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: spzenk/sfdocsamples
        static void Main(string[] args)
        {

            Console.SetWindowSize(60, 25);

            ThreadPool.SetMinThreads(4, 4);
            ThreadPool.SetMaxThreads(32, 32);

            EncryptType et = EncryptType.etNone;
            CompressionType ct = CompressionType.ctNone;
            int port = 8090;
            int connections = 50;

            if (args.Length >= 1)
            {
                port = Convert.ToInt32(args[0]);
            }

            if (args.Length >= 2)
            {
                et = (EncryptType) Enum.Parse(typeof(EncryptType), args[1], true);
            }

            if (args.Length >= 3)
            {
                ct = (CompressionType) Enum.Parse(typeof(CompressionType), args[2], true);
            }

            //----- Socket Client!
            OnEventDelegate FEvent = new OnEventDelegate(Event);

            SocketClient echoClient = new SocketClient(new EchoSocketService.EchoSocketService(FEvent));
            
            echoClient.Delimiter = new byte[] {0xAA, 0xFF};
            echoClient.DelimiterType = DelimiterType.dtMessageTailExcludeOnReceive;
            
            echoClient.SocketBufferSize = 4096;
            echoClient.MessageBufferSize = 4096 * 4;
            
            echoClient.IdleCheckInterval = 60000;
            echoClient.IdleTimeOutValue = 120000;

            //----- Socket Connectors!
            SocketConnector connector = null;
            
            for (int i = 0; i < connections; i++)
            {
                
                connector = echoClient.AddConnector("Connector " + i.ToString(), new IPEndPoint(IPAddress.Loopback, 8090));
                
                /*
                connector.ProxyInfo = new ProxyInfo(
                    ProxyType.ptHTTP, 
                    new IPEndPoint(IPAddress.Loopback, 8000), 
                    new NetworkCredential("user", "pass"));
                */
                
                connector.CryptoService =  new EchoCryptService.EchoCryptService();
                connector.CompressionType = ct;
                connector.EncryptType = et;

                connector.ReconnectAttempts = 2;
                connector.ReconnectAttemptInterval = 5000;
                
            }

            Console.Title = "EchoConsoleClient / " + connections.ToString() + " Connections / " + Enum.GetName(typeof(EncryptType), et) + " / " + Enum.GetName(typeof(CompressionType), ct);
            
            echoClient.Start();

            Console.WriteLine("Started!");
            Console.WriteLine("----------------------");

            Console.ReadLine();

            try
            {
                echoClient.Stop();
                echoClient.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            
            echoClient = null;

            Console.WriteLine("Stopped!");
            Console.WriteLine("----------------------");
            Console.ReadLine();

        }