示例#1
0
文件: Net2Client.cs 项目: cxdcxd/RRS
            protected override void _SocketBuilder()
            {
                if (info == null)
                {
                    info = GetAddress(name);
                    if (info == null)
                    {
                        Thread.Sleep(900);
                        return;
                    }
                }
                reportLog("Starting Dealer for ip " + info.Address + " and port " + info.Port, LogType.INFO, section);

                string path = "tcp://" + info.Address + ":" + info.Port;

                socket = new DealerSocket();

                socket.Options.TcpKeepalive         = true;
                socket.Options.TcpKeepaliveIdle     = TimeSpan.FromMilliseconds(100);
                socket.Options.TcpKeepaliveInterval = TimeSpan.FromMilliseconds(100);

                monitor = new NetMQMonitor(socket, "inproc://dealer" + Net2.GetAddressIndex(), SocketEvents.All);
                monitor.Disconnected += Monitor_Disconnected;
                monitor.Connected    += Monitor_Connected;
                monitor.Timeout       = TimeSpan.FromMilliseconds(100);
                task = Task.Factory.StartNew(monitor.Start);

                setState(Net2State.STARTED);
                start_time = GetTime().sec;

                socket.Connect(path);

                reportLog("Dealer is connected to " + path, LogType.INFO, section);
            }
示例#2
0
        private void Net2_service_delegateStateChanged(ulong id)
        {
            Net2HandlerBase instance = null;

            lock (@lock)
            {
                if (channels_list.ContainsKey(id))
                {
                    instance = channels_list[id];
                }
            }

            if (instance != null)
            {
                delegateInfoServiceStateChanged?.Invoke(instance);
            }
        }
示例#3
0
        private void Main_timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (state == Net2State.STARTED)
            {
                //net2_consul.advertiseService(NameSpace, 0, getStationIP(), getTime().sec.ToString());

                lock (@lock)
                {
                    Net2Base instance;
                    foreach (var item in channels_list.Values.Where(x => (x as INet2Handler).Instance != null &&
                                                                    ((x as INet2Handler).Instance is Net2Service) || (x as INet2Handler).Instance is Net2Publisher))
                    {
                        instance = (item as INet2Handler).Instance;
                        advertiseService(instance.Name, instance.LocalPort);
                    }
                }
            }
        }
示例#4
0
        private void ReleaseChannel(ulong id)
        {
            Net2Base instance = null;

            lock (@lock)
            {
                if (channels_list.ContainsKey(id))
                {
                    instance = (channels_list[id] as INet2Handler).Instance;
                    net2_consul.removeService(instance.Name);
                    channels_list.Remove(id);
                }
            }
            if (instance != null)
            {
                DeleteChannelsEvents(instance);
            }
        }
示例#5
0
        private byte[] ResponseCallback(long sequense, byte[] buffer, uint priority, ulong service_id)
        {
            Net2StationInfo station_info = new Net2StationInfo();

            station_info.host_name = NameSpace;
            station_info.ip        = "127.0.0.1";

            List <Net2HandlerBase> channels;

            lock (@lock)
            {
                int size = channels_list.Count;
                station_info.items = new Net2ServiceInfo[size];

                channels = channels_list.Values.ToList();
            }

            Net2Base instance;

            for (int i = 0; i < channels.Count; i++)
            {
                Net2ServiceInfo msg = new Net2ServiceInfo();
                instance = (channels[i] as INet2Handler).Instance;

                msg.name = instance.Name;

                msg.local_ip   = instance.LocalIp;
                msg.local_port = instance.LocalPort.ToString();

                msg.network_type = instance.GetType().ToString();
                msg.state        = instance.State.ToString();

                msg.connection_count = instance.ConnectionCount.ToString();
                msg.bytes_sent       = instance.BytesSend.ToString();
                msg.bytes_received   = instance.BytesReceive.ToString();

                station_info.items[i] = msg;
            }

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            ProtoBuf.Serializer.Serialize <Net2StationInfo>(ms, station_info);
            return(ms.ToArray());
        }
示例#6
0
            protected override void _SocketBuilder()
            {
                reportLog("Starting Router name " + Name, LogType.INFO, section);

                socket = new RouterSocket();

                socket.Options.TcpKeepalive         = true;
                socket.Options.TcpKeepaliveIdle     = TimeSpan.FromMilliseconds(100);
                socket.Options.TcpKeepaliveInterval = TimeSpan.FromMilliseconds(100);

                local_port = socket.BindRandomPort("tcp://*");

                monitor = new NetMQMonitor(socket, "inproc://router" + Net2.GetAddressIndex(), SocketEvents.All);
                monitor.Disconnected += Monitor_Disconnected;
                monitor.Accepted     += Monitor_Connected;
                monitor.Timeout       = TimeSpan.FromMilliseconds(100);
                task = monitor.StartAsync();

                setState(Net2State.STARTED);
                start_time = GetTime().sec;

                reportLog("Router is ready on " + local_port, LogType.INFO, section);
            }