Example #1
0
 private void updateStatus(VMusage.procVMinfo data)
 {
     //System.Diagnostics.Debug.WriteLine("updateStatus: " + data.dumpStatistics());
     if (this.onUpdate != null)
     {
         this.onUpdate(this, data);
     }
 }
Example #2
0
        public List <procVMinfo> getprocVmList(byte[] buf, string sIP)
        {
            List <procVMinfo> _mList = new List <procVMinfo>();
            int offset = 0;

            //is magic packet?
            if (ByteHelper.isLargePacket(buf))
            {
                offset += sizeof(UInt64);   //cut first bytes
            }
            try
            {
                while (offset < buf.Length)
                {
                    procVMinfo pi = new procVMinfo();
                    pi.remoteIP = sIP;
                    _mList.Add(pi.fromBytes(buf, ref offset));
                }
            }
            catch (Exception)
            {
            }
            return(_mList);
        }
Example #3
0
    void MessageReceivedCallback(IAsyncResult result)
    {
        EndPoint remoteEndPoint = new IPEndPoint(0, 0);

        //IPEndPoint LocalIPEndPoint = new IPEndPoint(IPAddress.Any, 3001);
        //EndPoint LocalEndPoint = (EndPoint)LocalIPEndPoint;
        //IPEndPoint remoteEP = (IPEndPoint)LocalEndPoint;
        //System.Diagnostics.Debug.WriteLine("Remote IP: " + remoteEP.Address.ToString());

        try
        {
            //all data should fit in one package!
            int bytesRead = receiveSocket.EndReceiveFrom(result, ref remoteEndPoint);
            //System.Diagnostics.Debug.WriteLine("Remote IP: " + ((IPEndPoint)(remoteEndPoint)).Address.ToString());

            byte[] bData = new byte[bytesRead];
            Array.Copy(recBuffer, bData, bytesRead);
            if (ByteHelper.isEndOfTransfer(bData))
            {
                System.Diagnostics.Debug.WriteLine("isEndOfTransfer");
                updateEndOfTransfer();// end of transfer
            }
            else if (ByteHelper.isMemInfoPacket(bData))
            {
                System.Diagnostics.Debug.WriteLine("isMemInfoPacket");
                try
                {
                    VMusage.MemoryInfoHelper mstat = new VMusage.MemoryInfoHelper();
                    mstat.fromByte(bData);

                    //System.Diagnostics.Debug.WriteLine(mstat.ToString());

                    updateMem(mstat);
                }
                catch (Exception) { }
            }
            else if (ByteHelper.isLargePacket(bData))
            {
                System.Diagnostics.Debug.WriteLine("isLargePacket");
                try
                {
                    List <procVMinfo>  lStats = new List <procVMinfo>();
                    VMusage.procVMinfo stats  = new VMusage.procVMinfo();
                    lStats = stats.getprocVmList(bData, ((IPEndPoint)(remoteEndPoint)).Address.ToString());
                    updateStatusBulk(lStats);
                    //foreach (procVMinfo pvmi in lStats)
                    //{
                    //    pvmi.remoteIP = ((IPEndPoint)(remoteEndPoint)).Address.ToString();
                    //    //System.Diagnostics.Debug.WriteLine( stats.dumpStatistics() );
                    //}
                }
                catch (Exception) { }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("trying vmUsagePacket...");
                try
                {
                    VMusage.procVMinfo stats = new VMusage.procVMinfo(bData);
                    stats.remoteIP = ((IPEndPoint)(remoteEndPoint)).Address.ToString();
                    //System.Diagnostics.Debug.WriteLine( stats.dumpStatistics() );
                    if (stats.Time == 0)
                    {
                        stats.Time = DateTime.Now.Ticks;
                    }
                    updateStatus(stats);
                }
                catch (Exception) { }
            }
        }
        catch (SocketException e)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("MessageReceivedCallback SocketException: {0} {1}", e.ErrorCode, e.Message));
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("MessageReceivedCallback Exception: {0}", e.Message));
        }
        try
        {
            //ready to receive next packet
            receiveSocket.BeginReceiveFrom(recBuffer, 0, recBuffer.Length, SocketFlags.None, ref bindEndPoint, new AsyncCallback(MessageReceivedCallback), (object)this);
        }
        catch (Exception) { }
    }
Example #4
0
 void listener_onUpdate(object sender, VMusage.procVMinfo data)
 {
     updateStatus(data);
 }
Example #5
0
        public List<procVMinfo> getprocVmList(byte[] buf, string sIP)
        {
            List<procVMinfo> _mList = new List<procVMinfo>();
            int offset = 0;

            //is magic packet?
            if (ByteHelper.isLargePacket(buf))
                offset += sizeof(UInt64);   //cut first bytes
            try
            {
                while (offset < buf.Length)
                {
                    procVMinfo pi = new procVMinfo();
                    pi.remoteIP = sIP;
                    _mList.Add(pi.fromBytes(buf, ref offset));
                }
            }
            catch (Exception)
            {

            }
            return _mList;
        }
Example #6
0
    void MessageReceivedCallback(IAsyncResult result)
    {
        EndPoint remoteEndPoint = new IPEndPoint(0, 0);

        //IPEndPoint LocalIPEndPoint = new IPEndPoint(IPAddress.Any, 3001);
        //EndPoint LocalEndPoint = (EndPoint)LocalIPEndPoint;
        //IPEndPoint remoteEP = (IPEndPoint)LocalEndPoint;
        //System.Diagnostics.Debug.WriteLine("Remote IP: " + remoteEP.Address.ToString());

        try
        {
            //all data should fit in one package!
            int bytesRead = receiveSocket.EndReceiveFrom(result, ref remoteEndPoint);
            //System.Diagnostics.Debug.WriteLine("Remote IP: " + ((IPEndPoint)(remoteEndPoint)).Address.ToString());

            byte[] bData = new byte[bytesRead];
            Array.Copy(recBuffer, bData, bytesRead);
            if (ByteHelper.isEndOfTransfer(bData))
            {
                System.Diagnostics.Debug.WriteLine("isEndOfTransfer");
                updateEndOfTransfer();// end of transfer
            }
            else if (ByteHelper.isMemInfoPacket(bData))
            {
                System.Diagnostics.Debug.WriteLine("isMemInfoPacket");
                try
                {
                    VMusage.MemoryInfoHelper mstat = new VMusage.MemoryInfoHelper();
                    mstat.fromByte(bData);

                    //System.Diagnostics.Debug.WriteLine(mstat.ToString());

                    updateMem(mstat);
                }
                catch (Exception) { }
            }
            else if(ByteHelper.isLargePacket(bData)){
                System.Diagnostics.Debug.WriteLine("isLargePacket");
                try
                {
                    List<procVMinfo> lStats = new List<procVMinfo>();
                    VMusage.procVMinfo stats = new VMusage.procVMinfo();
                    lStats = stats.getprocVmList(bData, ((IPEndPoint)(remoteEndPoint)).Address.ToString());
                    updateStatusBulk(lStats);
                    //foreach (procVMinfo pvmi in lStats)
                    //{
                    //    pvmi.remoteIP = ((IPEndPoint)(remoteEndPoint)).Address.ToString();
                    //    //System.Diagnostics.Debug.WriteLine( stats.dumpStatistics() );
                    //}
                }
                catch (Exception) { }

            }
            else
            {
                System.Diagnostics.Debug.WriteLine("trying vmUsagePacket...");
                try
                {
                    VMusage.procVMinfo stats = new VMusage.procVMinfo(bData);
                    stats.remoteIP = ((IPEndPoint)(remoteEndPoint)).Address.ToString();
                    //System.Diagnostics.Debug.WriteLine( stats.dumpStatistics() );
                    if (stats.Time == 0)
                        stats.Time = DateTime.Now.Ticks;
                    updateStatus(stats);
                }
                catch (Exception) { }
            }
        }
        catch (SocketException e)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("MessageReceivedCallback SocketException: {0} {1}", e.ErrorCode, e.Message));
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("MessageReceivedCallback Exception: {0}", e.Message));
        }
        try
        {
            //ready to receive next packet
            receiveSocket.BeginReceiveFrom(recBuffer, 0, recBuffer.Length, SocketFlags.None, ref bindEndPoint, new AsyncCallback(MessageReceivedCallback), (object)this);
        }
        catch (Exception) { }
    }