Пример #1
0
            protected override void OnRunThread()
            {
                Ip ip = null;

                try{
                    ip = new Ip(_addr);
                } catch (ValidObjException ex) {
                    Assert.Fail(ex.Message);
                }
                if (_sockServer.Bind(ip, _port))
                {
                    //[C#]
                    ThreadBaseKind = ThreadBaseKind.Running;

                    while (IsLife())
                    {
                        var child = (SockUdp)_sockServer.Select(this);
                        if (child == null)
                        {
                            break;
                        }
                        while (IsLife() && child.SockState == SockState.Connect)
                        {
                            var len = child.Length();
                            if (len > 0)
                            {
                                byte[] buf = child.RecvBuf;
                                child.Send(buf);
                                //送信が完了したら、この処理は終了
                                break;
                            }
                        }
                    }
                }
            }
Пример #2
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();
            }
Пример #3
0
        private void RunTcpServer(int port)
        {
            const int listenMax = 5;

            //[C#]
            ThreadBaseKind = ThreadBaseKind.Running;

            if (!_sockServer.Bind(_oneBind.Addr, port, listenMax))
            {
                Logger.Set(LogKind.Error, _sockServer, 9000006, _sockServer.GetLastEror());
            }
            else
            {
                while (IsLife())
                {
                    var child = (SockTcp)_sockServer.Select(this);
                    if (child == null)
                    {
                        break;
                    }
                    if (Count() >= _multiple)
                    {
                        Logger.Set(LogKind.Secure, _sockServer, 9000004, string.Format("count:{0}/multiple:{1}", Count(), _multiple));
                        //同時接続数を超えたのでリクエストをキャンセルします
                        child.Close();
                        continue;
                    }

                    // ACL制限のチェック
                    if (AclCheck(child) == AclKind.Deny)
                    {
                        child.Close();
                        continue;
                    }
                    lock (SyncObj){
                        var t = new Thread(SubThread)
                        {
                            IsBackground = true
                        };
                        t.Start(child);
                        _childThreads.Add(t);
                    }
                }
            }
        }
Пример #4
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));
            }