Beispiel #1
0
        private void OnGetInfo(Beetle.IChannel channel, string appname, IProperties properties)
        {
            HttpHeader  result;
            TrackerInfo info;

            byte[]             data;
            BytesReader        reader;
            HttpBody           body;
            IAppTrackerHandler appHandler = GetAppHandler(appname);

            if (appHandler == null)
            {
                result        = new HttpHeader();
                result.Action = "500 " + string.Format("{0} Tracker Handler Notfound", appname);
                channel.Send(result);
            }
            else
            {
                info          = appHandler.GetInfo(properties);
                data          = Encoding.UTF8.GetBytes(info.Data);
                result        = new HttpHeader();
                result.Action = "200";
                result.Length = data.Length;
                result[Protocol.HEADER_INFOTYPE] = info.TypeName;
                channel.Send(result);
                reader = new BytesReader(data, 0, data.Length);
                while (reader.Read())
                {
                    body = HttpPacket.InstanceBodyData();
                    reader.ReadTo(body);
                    channel.Send(body);
                }
            }
        }
Beispiel #2
0
        public void Stop(string ip, int port)
        {
            string _IpPorts = string.Format("{0}:{1}", ip, port);

            if (dict_Channel_Listen.ContainsKey(_IpPorts))
            {
                Beetle.IChannel _channel = dict_Channel_Listen[_IpPorts];
                if (_channel.Socket != null)
                {
                    _channel.Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
                }
                //    _channel.Socket.Disconnect(true);
                // _srv.Server.Socket.Disconnect(true);
                if (_channel.Server != null)
                {
                    _channel.Server.Dispose(); //
                }
                _channel.Dispose();            //
                dict_Channel_Listen.Remove(_IpPorts);
            }
            else if (!string.IsNullOrEmpty(_IpPorts))
            {
                //_srv.Server.Socket.Disconnect(true);
                if (_srv.Server != null)
                {
                    _srv.Server.Dispose();
                }
                _srv.Dispose();
            }
            else
            {
                MessageBox.Show("Stop(" + _IpPorts + ")");
            }
        }
Beispiel #3
0
        private void OnGet(Beetle.IChannel channel, string appname, IProperties properties)
        {
            IAppTrackerHandler appHandler = GetAppHandler(appname);

            if (appHandler == null)
            {
                HttpHeader result = new HttpHeader();
                result.Action = "500 " + string.Format("{0} Tracker Handler Notfound", appname);
                channel.Send(result);
            }
            else
            {
                AppHost apphost = appHandler.GetHost(properties);
                if (apphost == null)
                {
                    HttpHeader result = new HttpHeader();
                    result.Action = "500 App Host Notfound!";
                    channel.Send(result);
                }
                else
                {
                    HttpHeader result = new HttpHeader();
                    result.Action  = "200";
                    result["Host"] = apphost.Host;
                    result["Port"] = apphost.Port.ToString();
                    channel.Send(result);
                }
            }
        }
Beispiel #4
0
 public void OnRegister(Beetle.IChannel channel, Register e)
 {
     Console.WriteLine(e.UserName);
     Console.WriteLine(e.EMail);
     e.RegTime = DateTime.Now;
     channel.Send(e);
 }
Beispiel #5
0
 protected override void OnConnected(object sender, Beetle.ChannelEventArgs e)
 {
     base.OnConnected(sender, e);
     m_channel = e.Channel;
     if (hasEvent)
     {
         OnConnect(true, e);
     }
 }
Beispiel #6
0
 protected override void OnDisposed(object sender, Beetle.ChannelDisposedEventArgs e)
 {
     base.OnDisposed(sender, e);
     m_channel = null;
     if (hasEvent)
     {
         OnConnect(false, (Beetle.ChannelEventArgs)e);
     }
 }
Beispiel #7
0
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     try
     {
         mChannel = Beetle.TcpServer.CreateClient<Beetle.Protobuf.Package>(
             txtIPAddress.Text, 9321, OnReveive);
         mChannel.ChannelDisposed += OnDisposed;
         cmdRegister.Enabled = !(cmdConnect.Enabled = false);
         mChannel.BeginReceive();
     }
     catch (Exception e_)
     {
         MessageBox.Show(e_.Message);
     }
 }
Beispiel #8
0
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     try
     {
         mChannel = Beetle.TcpServer.CreateClient <Beetle.Protobuf.Package>(
             txtIPAddress.Text, 9321, OnReveive);
         mChannel.ChannelDisposed += OnDisposed;
         cmdRegister.Enabled       = !(cmdConnect.Enabled = false);
         mChannel.BeginReceive();
     }
     catch (Exception e_)
     {
         MessageBox.Show(e_.Message);
     }
 }
Beispiel #9
0
 private void cmdConnetc_Click(object sender, EventArgs e)
 {
     try
     {
         channel = Beetle.TcpServer.CreateClient<Messages.HeadSizePackage>(txtIPAddress.Text, 9450,OnReceive);
         channel.ChannelDisposed += OnDisposed;
         channel.ChannelError += OnError;
         channel.BeginReceive();
         cmdRegister.Enabled = true;
     }
     catch (Exception e_)
     {
         MessageBox.Show(e_.Message);
     }
 }
Beispiel #10
0
 private void cmdConnetc_Click(object sender, EventArgs e)
 {
     try
     {
         channel = Beetle.TcpServer.CreateClient <EncryptPackage>(txtIPAddress.Text, 8088, OnReceive);
         channel.ChannelDisposed += OnDisposed;
         channel.ChannelError    += OnError;
         channel.BeginReceive();
         cmdRegister.Enabled = true;
     }
     catch (Exception e_)
     {
         MessageBox.Show(e_.Message);
     }
 }
Beispiel #11
0
        // 连接方法主动发连接事件
        public bool do_Connect(string ip, int port)
        {
            if (_Connected)
            {
                return(true);
            }
            IP   = ip;
            Port = port;
            try
            {
                m_channel = Beetle.TcpServer.CreateClient(ip, port); // 连接到指定IP的端口服务
                System.Threading.Thread.Sleep(100);

                m_channel.ChannelDisposed += _evt_Disposed;     // 连接断开事件
                m_channel.DataReceive      = _evt_DataReceived; // 绑定数据流接收事件
                m_channel.ChannelError    += (o, err) =>        // 组件错误
                {
                    Console.WriteLine(err.Exception.Message);
                };
                m_channel.BeginReceive();                // 开始接收数据
                _Connected = m_channel.Socket.Connected; // ;
                if (_Connected)
                {
                    IP   = ip;
                    Port = port;
                    if (hasEvent)
                    {
                        OnConnect(_Connected, string.Format("{0}:{1}", IP, Port));
                    }
                }
                return(_Connected);// m_channel.Socket.Connected;
            }
            catch (System.Net.Sockets.SocketException ex_)
            {
                ErrorCode = -101;
                // MessageBox.Show("-101: 请确认[" + ip + ":" + port.ToString() + "]服务器已打开. ");
                Console.WriteLine(ex_.Message); // 由于目标计算机积极拒绝,无法连接
            }
            catch (Exception e_)
            {
                ErrorCode = -100;
                MessageBox.Show("-100:" + e_.Message);
                //Console.WriteLine(e_.Message);
            }
            return(false);
        }
Beispiel #12
0
        private void OnRegister(Beetle.IChannel channel, string appName, IProperties properties)
        {
            IAppTrackerHandler appHandler;
            HttpHeader         result;
            IProperties        ips;

            appHandler = GetAppHandler(appName);
            if (appHandler == null)
            {
                result        = new HttpHeader();
                result.Action = RESULT_STATE_500 + string.Format(ERROR_MSG_TRACKER_NOTFOUND, appName);
                channel.Send(result);
            }
            else
            {
                ips           = appHandler.Register(properties);
                result        = this.GetResponse(ips);
                result.Action = RESULT_STATE_200;
                channel.Send(result);
            }
        }
Beispiel #13
0
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     try
     {
         //连接到指定IP的端口服务
         channel = Beetle.TcpServer.CreateClient(txtIPAddress.Text, 9321);
         //绑定数据流接收事件
         channel.DataReceive = OnReceive;
         //连接断开事件
         channel.ChannelDisposed += OnDisposed;
         channel.ChannelError    += (o, err) => {
             System.Console.WriteLine(err.Exception.Message);
         };
         //开始接收数据
         channel.BeginReceive();
         cmdSend.Enabled    = true;
         cmdConnect.Enabled = false;
     }
     catch (Exception e_)
     {
         MessageBox.Show(e_.Message);
     }
 }
Beispiel #14
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            try
            {
                //连接到指定IP的端口服务
                channel = Beetle.TcpServer.CreateClient(txtIPAddress.Text, 9321);
                //绑定数据流接收事件
                channel.DataReceive = OnReceive;
                //连接断开事件
                channel.ChannelDisposed += OnDisposed;
                channel.ChannelError += (o, err) => {
                    System.Console.WriteLine(err.Exception.Message);
                };
                //开始接收数据
                channel.BeginReceive();
                cmdSend.Enabled = true;
                cmdConnect.Enabled = false;
            }
            catch (Exception e_)
            {
                MessageBox.Show(e_.Message);
            }

        }
Beispiel #15
0
 public Package(Beetle.IChannel channel)
     : base(channel)
 {
 }
Beispiel #16
0
 public NPPacakge(Beetle.IChannel channel)
     : base(channel)
 {
 }
Beispiel #17
0
 public HeadSizePage(Beetle.IChannel channel)
     : base(channel)
 {
 }