程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#挪用mmpeg停止各類視頻轉換的類實例

C#挪用mmpeg停止各類視頻轉換的類實例

編輯:C#入門知識

C#挪用mmpeg停止各類視頻轉換的類實例。本站提示廣大學習愛好者:(C#挪用mmpeg停止各類視頻轉換的類實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C#挪用mmpeg停止各類視頻轉換的類實例正文


本文為年夜家分享了模仿Ping操作的一個Java類,詳細內容以下

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
 
/**
 * Created by QiuJU
 * on 2014/9/21.
 */
public class SimplePing implements Runnable {
 private final Object mEndLock = new Object();
 private boolean IsEnd = false;
 
 private int arrivedCount = 0;
 
 private int Count;
 private int TimeOut;
 private String Name;
 
 private int mEndCount;
 private String mIp = null;
 private float mLossRate = 1f;
 private float mDelay = 0;
 
 
 public SimplePing(String name, int count, int timeOut) {
  Count = mEndCount = count;
  TimeOut = timeOut;
  Name = name;
  for (int i = 0; i < mEndCount; i++) {
   Thread thread = new Thread(this);
   thread.setDaemon(true);
   thread.start();
  }
  if (!IsEnd) {
   try {
    synchronized (mEndLock) {
     mEndLock.wait();
    }
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
  }
 }
 
 private void setEnd(boolean isArrived, long delay, String ip) {
  synchronized (mEndLock) {
   Count--;
   if (isArrived) {
    arrivedCount++;
    mDelay = (mDelay + delay) / 2f;
    if (ip != null)
     mIp = ip;
   }
  }
  if (Count == 0)
   setEnd();
 }
 
 private void setEnd() {
  mLossRate = (mEndCount - arrivedCount) / mEndCount;
 
  IsEnd = true;
  synchronized (mEndLock) {
   mEndLock.notifyAll();
  }
 }
 
 @Override
 public void run() {
  long delay = 0;
  boolean isArrived = false;
  String ip = null;
  try {
   long startTime = System.currentTimeMillis();
   InetAddress address = InetAddress.getByName(Name);
   isArrived = address.isReachable(TimeOut);
   delay = System.currentTimeMillis() - startTime;
   ip = address.getHostAddress();
  } catch (UnknownHostException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   setEnd(isArrived, delay, ip);
  }
 }
 
 public String getIp() {
  return mIp;
 }
 
 public float getLossRate() {
  return mLossRate;
 }
 
 public float getDelay() {
  return mDelay;
 }
 
 public boolean getIsSucceed() {
  return arrivedCount > 0;
 }
}

在類中應用的是:

long startTime = System.currentTimeMillis();
   InetAddress address = InetAddress.getByName(Name);
   isArrived = address.isReachable(TimeOut);
   delay = System.currentTimeMillis() - startTime;
   ip = address.getHostAddress();

個中的:address.isReachable(TimeOut);辦法,然則這個辦法有必定局限性;當是Root形式下會發送ICMP停止Ping操作,這就比擬真實了;然則假如長短Root形式下則是應用的Socket停止的模仿。
之所以說是中央類,也就是由於這個緣由沒有采取這個類。

以上就是本文的全體內容,願望對年夜家的進修有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved