Exemple #1
0
            public void getLocalAddress(String title, ProtocolKind protocolKind)
            {
                var bindIp = new Ip(IpKind.V4Localhost);
                const int port = 9991;
                const int listenMax = 10;
                Ssl ssl = null;

                var sockServer = new SockServer(new Kernel(),protocolKind,ssl);

                ThreadStart action = () =>{
                    if (protocolKind == ProtocolKind.Tcp){
                        sockServer.Bind(bindIp, port, listenMax);
                    }else{
                        sockServer.Bind(bindIp, port);
                    }};

                var _t = new Thread(action) { IsBackground = true };
                _t.Start();

                while (sockServer.SockState == SockState.Idle){
                    Thread.Sleep(200);
                }

                var localAddress = sockServer.LocalAddress;
                Assert.That(localAddress.ToString(), Is.EqualTo("127.0.0.1:9991"));
                //bind()後 localAddressの取得が可能になる

                var remoteAddress = sockServer.RemoteAddress;
                Assert.IsNull(remoteAddress);
                //SockServerでは、remoteAddressは常にnullになる

                sockServer.Close();
            }
Exemple #2
0
            public void startStop(String title, ProtocolKind protocolKind)
            {
                var bindIp = new Ip(IpKind.V4Localhost);
                const int port = 8881;
                const int listenMax = 10;
                Ssl ssl= null;

                var sockServer = new SockServer(new Kernel(),protocolKind,ssl);

                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Idle));

                ThreadStart action = () =>  {
                    if (protocolKind == ProtocolKind.Tcp){
                        sockServer.Bind(bindIp, port, listenMax);
                    } else{
                        sockServer.Bind(bindIp, port);
                    }
                };

                var _t = new Thread(action) { IsBackground = true };
                _t.Start();

                while (sockServer.SockState == SockState.Idle){
                    Thread.Sleep(100);
                }
                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Bind));
                sockServer.Close(); //bind()にThreadBaseのポインタを送っていないため、isLifeでブレイクできないので、selectで例外を発生させて終了する
                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Error));
            }
Exemple #3
0
        public TestServer(ProtocolKind protocolKind, int port) : base("WebServer", protocolKind, port)
        {
            //通常は、NameTagの初期化は、baseのコンストラクタへのパラメータで行われる
            //Webの場合は、特別
            NameTag = string.Format("Web-{0}:{1}", hostName, port);

            //ドキュメントルートの設定
            //テストコードのフォルダにドキュメントルートを設定する
            DocumentRoot = UtilDir.Src + "\\public_html";
            SetOption("FOLDER", "documentRoot", DocumentRoot);
        }
Exemple #4
0
        public TestServer(ProtocolKind protocolKind,int port)
            : base("WebServer",protocolKind,port)
        {
            //通常は、NameTagの初期化は、baseのコンストラクタへのパラメータで行われる
            //Webの場合は、特別
            NameTag = string.Format("Web-{0}:{1}", hostName, port);

            //ドキュメントルートの設定
            //テストコードのフォルダにドキュメントルートを設定する
            DocumentRoot = UtilDir.Src + "\\public_html";
            SetOption("FOLDER", "documentRoot", DocumentRoot);
        }
Exemple #5
0
        public void CreateOneBindで生成される数の確認(string bindStr, ProtocolKind protocolKind, int count, string firstOneBind)
        {
            //stUp
            var sut = new BindAddr(bindStr);
            var expected = count;

            //exercise
            var ar = sut.CreateOneBind(protocolKind);
            var actual = ar.Length;
            //verify
            Assert.That(actual, Is.EqualTo(expected));
        }
Exemple #6
0
        public void CreateOneBindで生成される数の確認(string bindStr, ProtocolKind protocolKind, int count, string firstOneBind)
        {
            //stUp
            var sut      = new BindAddr(bindStr);
            var expected = count;

            //exercise
            var ar     = sut.CreateOneBind(protocolKind);
            var actual = ar.Length;

            //verify
            Assert.That(actual, Is.EqualTo(expected));
        }
Exemple #7
0
        private static Protocol Convert(ProtocolKind protocol)
        {
            switch (protocol)
            {
            case ProtocolKind.Tcp:
                return(Protocol.Tcp);

            case ProtocolKind.Udp:
                return(Protocol.Udp);

            default:
                throw new ArgumentOutOfRangeException(nameof(protocol), protocol, null);
            }
        }
Exemple #8
0
        //プロトコルを指定してOneBindの配列を取得
        //取得した配列分だけインターフェースへのbindが必要となる
        public OneBind[] CreateOneBind(ProtocolKind protocolKind)
        {
            CheckInitialise();
            var ar = new List <OneBind>();

            if (BindStyle != BindStyle.V4Only)
            {
                ar.Add(new OneBind(IpV6, protocolKind));
            }
            if (BindStyle != BindStyle.V6Only)
            {
                ar.Add(new OneBind(IpV4, protocolKind));
            }
            return(ar.ToArray());
        }
Exemple #9
0
        //�R���X�g���N�^
        public Server(Kernel kernel,Conf conf,OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            _targetServer = (string)Conf.Get("targetServer");
            _targetPort = (int)Conf.Get("targetPort");

            if (_targetServer == "") {
                Logger.Set(LogKind.Error,null, 1, "");
            }
            if (_targetPort == 0) {
                Logger.Set(LogKind.Error, null,2, "");
            }

            _protocolKind = oneBind.Protocol;
        }
Exemple #10
0
        //�R���X�g���N�^
        public Server(Kernel kernel, Conf conf, OneBind oneBind)
            : base(kernel, conf, oneBind)
        {
            _targetServer = (string)Conf.Get("targetServer");
            _targetPort   = (int)Conf.Get("targetPort");

            if (_targetServer == "")
            {
                Logger.Set(LogKind.Error, null, 1, "");
            }
            if (_targetPort == 0)
            {
                Logger.Set(LogKind.Error, null, 2, "");
            }

            _protocolKind = oneBind.Protocol;
        }
Exemple #11
0
            public void getLocalAddress(String title, ProtocolKind protocolKind)
            {
                var       bindIp    = new Ip(IpKind.V4Localhost);
                const int port      = 9991;
                const int listenMax = 10;
                Ssl       ssl       = null;

                var sockServer = new SockServer(new Kernel(), protocolKind, ssl);

                ThreadStart action = () => {
                    if (protocolKind == ProtocolKind.Tcp)
                    {
                        sockServer.Bind(bindIp, port, listenMax);
                    }
                    else
                    {
                        sockServer.Bind(bindIp, port);
                    }
                };


                var _t = new Thread(action)
                {
                    IsBackground = true
                };

                _t.Start();

                while (sockServer.SockState == SockState.Idle)
                {
                    Thread.Sleep(200);
                }

                var localAddress = sockServer.LocalAddress;

                Assert.That(localAddress.ToString(), Is.EqualTo("127.0.0.1:9991"));
                //bind()後 localAddressの取得が可能になる

                var remoteAddress = sockServer.RemoteAddress;

                Assert.IsNull(remoteAddress);
                //SockServerでは、remoteAddressは常にnullになる

                sockServer.Close();
            }
Exemple #12
0
        //OneValとしてサーバ基本設定を作成する
        protected OneVal CreateServerOption(ProtocolKind protocolKind, int port, int timeout, int multiple)
        {
            var list = new ListVal();

            list.Add(new OneVal("protocolKind", protocolKind, Crlf.Contonie, new CtrlComboBox(_isJp ? "プロトコル"
                                : "Protocol", new [] { "TCP", "UDP" }, 60)));
            list.Add(new OneVal("port", port, Crlf.Nextline, new CtrlInt(_isJp ? "クライアントから見たポート" : "Port (from client side)", 5)));
            var localAddress = LocalAddress.GetInstance();
            var v4           = localAddress.V4;
            var v6           = localAddress.V6;

            list.Add(new OneVal("bindAddress2", new BindAddr(), Crlf.Nextline, new CtrlBindAddr(_isJp ? "待ち受けるネットワーク": "Bind Address", v4, v6)));
            list.Add(new OneVal("useResolve", false, Crlf.Nextline, new CtrlCheckBox((_isJp ? "クライアントのホスト名を逆引きする": "Reverse pull of host name from IP address"))));
            list.Add(new OneVal("useDetailsLog", true, Crlf.Contonie, new CtrlCheckBox(_isJp ? "詳細ログを出力する": "Use Details Log")));
            list.Add(new OneVal("multiple", multiple, Crlf.Contonie, new CtrlInt(_isJp ? "同時接続数" : "A repetition thread", 5)));
            list.Add(new OneVal("timeOut", timeout, Crlf.Nextline, new CtrlInt(_isJp ? "タイムアウト(秒)" : "Timeout", 6)));
            return(new OneVal("GroupServer", null, Crlf.Nextline, new CtrlGroup(_isJp ? "サーバ基本設定" : "Server Basic Option", list)));
        }
Exemple #13
0
            public void startStop(String title, ProtocolKind protocolKind)
            {
                var       bindIp    = new Ip(IpKind.V4Localhost);
                const int port      = 8881;
                const int listenMax = 10;
                Ssl       ssl       = null;

                var sockServer = new SockServer(new Kernel(), protocolKind, ssl);

                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Idle));

                ThreadStart action = () => {
                    if (protocolKind == ProtocolKind.Tcp)
                    {
                        sockServer.Bind(bindIp, port, listenMax);
                    }
                    else
                    {
                        sockServer.Bind(bindIp, port);
                    }
                };

                var _t = new Thread(action)
                {
                    IsBackground = true
                };

                _t.Start();


                while (sockServer.SockState == SockState.Idle)
                {
                    Thread.Sleep(100);
                }
                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Bind));
                sockServer.Close(); //bind()にThreadBaseのポインタを送っていないため、isLifeでブレイクできないので、selectで例外を発生させて終了する
                Assert.That(sockServer.SockState, Is.EqualTo(SockState.Error));
            }
Exemple #14
0
 public OneBind(Ip addr, ProtocolKind protocol)
 {
     Addr     = addr;
     Protocol = protocol;
 }
Exemple #15
0
        //Ver5.9.2 Java fix
        //private OneSsl _oneSsl;

        public SockServer(Kernel kernel, ProtocolKind protocolKind, Ssl ssl) : base(kernel)
        {
            ProtocolKind = protocolKind;
            _ssl         = ssl;
        }
Exemple #16
0
 //プロトコルを指定してOneBindの配列を取得
 //取得した配列分だけインターフェースへのbindが必要となる
 public OneBind[] CreateOneBind(ProtocolKind protocolKind)
 {
     CheckInitialise();
     var ar = new List<OneBind>();
     if (BindStyle != BindStyle.V4Only){
         ar.Add(new OneBind(IpV6, protocolKind));
     }
     if (BindStyle != BindStyle.V6Only){
         ar.Add(new OneBind(IpV4, protocolKind));
     }
     return ar.ToArray();
 }
Exemple #17
0
 public EchoServer(Conf conf, OneBind oneBind)
     : base(new Kernel(), conf, oneBind)
 {
     _protocolKind = oneBind.Protocol;
 }
Exemple #18
0
 //Ver5.9.2 Java fix
 //private OneSsl _oneSsl;
 public SockServer(Kernel kernel,ProtocolKind protocolKind,Ssl ssl)
     : base(kernel)
 {
     ProtocolKind = protocolKind;
     _ssl = ssl;
 }
Exemple #19
0
 //OneValとしてサーバ基本設定を作成する
 protected OneVal CreateServerOption(ProtocolKind protocolKind, int port, int timeout, int multiple)
 {
     var list = new ListVal();
     list.Add(new OneVal("protocolKind", protocolKind, Crlf.Contonie, new CtrlComboBox(_isJp ? "プロトコル"
         : "Protocol", new [] { "TCP", "UDP" }, 60)));
     list.Add(new OneVal("port", port, Crlf.Nextline, new CtrlInt(_isJp ? "クライアントから見たポート" : "Port (from client side)", 5)));
     var localAddress = LocalAddress.GetInstance();
     var v4 = localAddress.V4;
     var v6 = localAddress.V6;
     list.Add(new OneVal("bindAddress2", new BindAddr(), Crlf.Nextline, new CtrlBindAddr(_isJp ? "待ち受けるネットワーク": "Bind Address", v4, v6)));
     list.Add(new OneVal("useResolve", false, Crlf.Nextline, new CtrlCheckBox((_isJp ? "クライアントのホスト名を逆引きする": "Reverse pull of host name from IP address"))));
     list.Add(new OneVal("useDetailsLog", true, Crlf.Contonie, new CtrlCheckBox(_isJp ? "詳細ログを出力する": "Use Details Log")));
     list.Add(new OneVal("multiple", multiple, Crlf.Contonie, new CtrlInt(_isJp ? "同時接続数" : "A repetition thread", 5)));
     list.Add(new OneVal("timeOut", timeout, Crlf.Nextline, new CtrlInt(_isJp ? "タイムアウト(秒)" : "Timeout", 6)));
     return new OneVal("GroupServer", null, Crlf.Nextline, new CtrlGroup(_isJp ? "サーバ基本設定" : "Server Basic Option",list));
 }
Exemple #20
0
 public EchoServer(Conf conf, OneBind oneBind) : base(new Kernel(), conf, oneBind)
 {
     _protocolKind = oneBind.Protocol;
 }
Exemple #21
0
 public OneBind(Ip addr,ProtocolKind protocol)
 {
     Addr = addr;
     Protocol = protocol;
 }