コード例 #1
0
ファイル: UIData.cs プロジェクト: yonzkon/mnncs
        public void DelSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                SockUnit unit = FindSockUnit(type, lep, rep);
                if (unit == null)
                {
                    return;
                }

                switch (type)
                {
                case SockType.listen:
                case SockType.connect:
                    SockUnitGroup.Remove(unit);
                    break;

                case SockType.accept:
                    var subset = from s in SockUnitGroup
                                 where s.Type == SockType.listen && s.Lep.Port == unit.Lep.Port
                                 select s;
                    if (subset.Count() != 0)
                    {
                        subset.First().Childs.Remove(unit);
                        CurrentAcceptCount--;
                        HistoryAcceptCloseCount++;
                    }
                    break;
                }
            }));
        }
コード例 #2
0
ファイル: UIData.cs プロジェクト: yonzkon/mnncs
 public void CloseSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit != null)
         {
             unit.State = SockState.Closed;
         }
     }));
 }
コード例 #3
0
ファイル: AwesomeSocket.cs プロジェクト: yufc/AwesomeSockets
        internal static AwesomeSocket New(SockType sockType = SockType.Tcp)
        {
            switch (sockType)
            {
            case SockType.Udp:
                return(new AwesomeSocket(AddressFamily.InterNetwork, SocketType.Dgram));

            default:
                return(new AwesomeSocket());
            }
        }
コード例 #4
0
ファイル: D2Socket.cs プロジェクト: inrg/BioBot
 public D2Socket(SockType Type)
 {
     base.Disconnection += new Sockets.DisconnectionEventHandler(this.D2Socket_Disconnection);
     base.Connection    += new Sockets.ConnectionEventHandler(this.D2Socket_Connection);
     this.Firstpacket    = true;
     this.PacketInWait   = new SortedList();
     this.SocketType     = Type;
     this.PacketWaiting  = new Thread(new ThreadStart(this.Waiting));
     this.PacketWaiting.IsBackground = true;
     this.PacketWaiting.Start();
 }
コード例 #5
0
        // Methods ============================================================================

        public SockSess(SockType type, Socket sock)
        {
            this.type = type;
            this.sock = sock;
            eof       = false;
            tick      = DateTime.Now;
            conntime  = tick;
            id        = Guid.NewGuid().ToString();

            rdata      = new byte[rdata_max];
            wdata      = new byte[wdata_max];
            this.sdata = null;
        }
コード例 #6
0
ファイル: UIData.cs プロジェクト: yonzkon/mnncs
 public void OpenSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep, string sessid)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit == null)
         {
             return;
         }
         unit.Lep    = lep;
         unit.Rep    = rep;
         unit.SESSID = sessid;
         unit.State  = SockState.Opened;
     }));
 }
コード例 #7
0
ファイル: CoreBaseNew.cs プロジェクト: yiend/mnncs
        protected SockSessNew FindSockSessFromSessGroup(SockType sockType, IPEndPoint ep)
        {
            IEnumerable<SockSessNew> subset = null;
            switch (sockType) {
                case SockType.listen:
                case SockType.connect:
                    subset = from s in sess_group where s.lep.Equals(ep) select s;
                    break;
                case SockType.accept:
                    subset = from s in sess_group where s.rep != null && s.rep.Equals(ep) select s;
                    break;
                default:
                    break;
            }

            if (subset != null && subset.Count() != 0)
                return subset.First();
            else
                return null;
        }
コード例 #8
0
        public SockSess FindSession(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            ThreadCheck(false);

            SockSess retval = null;

            switch (type)
            {
            case SockType.listen:
            case SockType.connect:
                foreach (var item in sess_table)
                {
                    if (item.type == type && item.lep.Equals(lep))
                    {
                        retval = item;
                        break;
                    }
                }
                break;

            case SockType.accept:
                foreach (var item in sess_table)
                {
                    if (item.type == type && item.rep.Equals(rep))
                    {
                        retval = item;
                        break;
                    }
                }
                break;

            default:
                break;
            }

            return(retval);
        }
コード例 #9
0
ファイル: UIData.cs プロジェクト: yonzkon/mnncs
        private SockUnit FindSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            IEnumerable <SockUnit> subset = null;

            if (type == SockType.listen)
            {
                subset = from s in SockUnitGroup where s.Type == type && s.Lep.Equals(lep) select s;
            }
            else if (type == SockType.connect)
            {
                subset = from s in SockUnitGroup where s.Type == type && s.Rep.Equals(rep) select s;
            }
            else if (type == SockType.accept)
            {
                foreach (var item in SockUnitGroup)
                {
                    subset = from s in item.Childs where s.Rep.Equals(rep) select s;
                    if (subset.Count() != 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                return(null);
            }

            if (subset != null && subset.Count() != 0)
            {
                return(subset.First());
            }
            else
            {
                return(null);
            }
        }
コード例 #10
0
ファイル: SockSess.cs プロジェクト: yiend/mnncs
        public SockSess FindSession(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            ThreadCheck(false);

            SockSess retval = null;

            switch (type) {
                case SockType.listen:
                case SockType.connect:
                    foreach (var item in sess_table) {
                        if (item.type == type && item.lep.Equals(lep)) {
                            retval = item;
                            break;
                        }
                    }
                    break;
                case SockType.accept:
                    foreach (var item in sess_table) {
                        if (item.type == type && item.rep.Equals(rep)) {
                            retval = item;
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }

            return retval;
        }
コード例 #11
0
ファイル: DataUI.cs プロジェクト: yiend/mnncs
 public void CloseSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
 {
     System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => {
         SockUnit unit = FindSockUnit(type, lep, rep);
         if (unit != null)
             unit.State = SockState.Closed;
     }));
 }
コード例 #12
0
 internal static AwesomeSocket New(SockType sockType = SockType.Tcp)
 {
     switch (sockType)
     {
         case SockType.Udp:
             return new AwesomeSocket(AddressFamily.InterNetwork, SocketType.Dgram);
         default:
             return new AwesomeSocket();
     }
 }
コード例 #13
0
ファイル: DataUI.cs プロジェクト: yiend/mnncs
        private SockUnit FindSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            IEnumerable<SockUnit> subset = null;
            if (type == SockType.listen)
                subset = from s in SockUnitGroup where s.Type == type && s.Lep.Equals(lep) select s;
            else if (type == SockType.connect)
                subset = from s in SockUnitGroup where s.Type == type && s.Lep != null && s.Lep.Equals(lep) select s;
            else if (type == SockType.accept) {
                foreach (var item in SockUnitGroup) {
                    subset = from s in item.Childs where s.Rep.Equals(rep) select s;
                    if (subset.Count() != 0)
                        break;
                }
            }
            else
                return null;

            if (subset != null && subset.Count() != 0)
                return subset.First();
            else
                return null;
        }
コード例 #14
0
ファイル: DataUI.cs プロジェクト: yiend/mnncs
        public void DelSockUnit(SockType type, IPEndPoint lep, IPEndPoint rep)
        {
            System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                SockUnit unit = FindSockUnit(type, lep, rep);
                if (unit == null) return;

                switch (type) {
                    case SockType.listen:
                    case SockType.connect:
                        SockUnitGroup.Remove(unit);
                        break;

                    case SockType.accept:
                        var subset = from s in SockUnitGroup
                                     where s.Type == SockType.listen && s.Lep.Port == unit.Lep.Port
                                     select s;
                        if (subset.Count() != 0) {
                            subset.First().Childs.Remove(unit);
                            CurrentAcceptCount--;
                            HistoryAcceptCloseCount++;
                        }
                        break;
                }
            }));
        }
コード例 #15
0
ファイル: SockSess.cs プロジェクト: yiend/mnncs
        // Methods ============================================================================
        public SockSess(SockType type, Socket sock)
        {
            this.type = type;
            this.sock = sock;
            lep = sock.LocalEndPoint as IPEndPoint;
            rep = type == SockType.listen ? null : sock.RemoteEndPoint as IPEndPoint;
            eof = false;
            tick = DateTime.Now;

            rdata = new byte[rdata_max];
            wdata = new byte[wdata_max];
            this.sdata = null;
        }
コード例 #16
0
ファイル: MainWindow.xaml.cs プロジェクト: yonzkon/mnncs
        public void Config()
        {
            if (File.Exists(BASE_DIR + CONF_NAME) == false)
            {
                System.Windows.MessageBox.Show(CONF_NAME + ": can't find it.");
                return;
            }

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load(BASE_DIR + CONF_NAME);

                // cmdtable
                foreach (XmlNode item in doc.SelectNodes("/configuration/commands/cmditem"))
                {
                    CmdUnit cmd = new CmdUnit();
                    cmd.ID          = item.Attributes["id"].Value;
                    cmd.Name        = item.Attributes["name"].Value;
                    cmd.Cmd         = item.Attributes["content"].Value;
                    cmd.Encrypt     = bool.Parse(item.Attributes["encrypt"].Value);
                    cmd.ContentMode = (ServiceRequestContentMode)Enum.Parse(typeof(ServiceRequestContentMode), item.Attributes["content-mode"].Value);
                    uidata.CmdTable.Add(cmd);
                }

                /// sockunit
                foreach (XmlNode item in doc.SelectNodes("/configuration/sockets/sockitem"))
                {
                    string[]   str      = item.Attributes["ep"].Value.Split(':');
                    IPEndPoint ep       = new IPEndPoint(IPAddress.Parse(str[0]), int.Parse(str[1]));
                    SockType   sockType = (SockType)Enum.Parse(typeof(SockType), item.Attributes["type"].Value);
                    SockUnit   sockUnit = new SockUnit()
                    {
                        ID      = item.Attributes["id"].Value,
                        Name    = item.Attributes["name"].Value,
                        Type    = sockType,
                        Lep     = sockType == SockType.listen ? ep : null,
                        Rep     = sockType == SockType.connect ? ep : null,
                        State   = SockState.Closed,
                        Autorun = bool.Parse(item.Attributes["autorun"].Value),
                    };
                    uidata.AddSockUnit(sockUnit);

                    if (sockUnit.Autorun)
                    {
                        string id = "service.sesslisten";
                        if (sockType == SockType.connect)
                        {
                            id = "service.sessconnect";
                        }
                        object req = new {
                            id   = id,
                            ip   = ep.Address.ToString(),
                            port = ep.Port,
                        };
                        core.AddServiceRequest(ServiceRequest.Parse(JsonConvert.SerializeObject(req)));
                    }
                }
            } catch (Exception) {
                System.Windows.MessageBox.Show(CONF_NAME + ": syntax error.");
            }
        }
コード例 #17
0
ファイル: Core.cs プロジェクト: yiend/mnncs
 private void SockOpen(string id, SockType sockType, IPEndPoint ep)
 {
     try {
         SockSessNew sess = null;
         if (sockType == SockType.listen)
             sess = MakeListen(ep);
         else
             sess = MakeConnect(ep);
         DataUI.OpenSockUnit(id, sess.lep, sess.rep);
     } catch (Exception) {
         DataUI.CloseSockUnit(id);
     }
 }