【正文】
= 4。 = new (96, 35)。 = new ()。 private timer1。 } // Find the appropriate encoder // 查找合適的編碼器 private ImageCodecInfo GetEncoderInfo(String mimeType) { int j。 if (b) { m_PacketCount++。 19 // Empty the stream //清空流 (0)。 } ()。 serv = new TcpServer(TCPLISTENPORT, ()[3])。 } /// summary /// Stop this service. /// 停止服務 /// The Run() Method tests for this thread state each second /// 每秒都為這個進程啟動方法測試 /// /summary protected override void OnStop() { 16 // Set exit condition //設置退出狀態(tài) bShutDown = true。 = WebCamService。 } 13 } } } // Remove a connection from the list of active connections private void RemoveConnection(SockWrapper s) { try { ( )。 lock (this) { if (!m_bShuttingDown) { // Wrap the client and add it to the array SockWrapper s = new SockWrapper(client)。 private void _TcpServer(int nPortListen, IPAddress ip) { try 10 { // Initialize member vars m_aryClients = new ArrayList(5)。 t = new TcpClient((), )。 if USING_NET11 IPHostEntry ipEntry = ( strHostName )。 客戶端連接是指由客戶端的 socket 提出連接請求,要連接的目標是服務器端的 socket。 IP數(shù)據(jù)包是不可靠的,因為 IP并沒有做任何事情來確認數(shù)據(jù)包是按順序發(fā)送的或者沒有被破壞。 DirectShow 為多媒體流的捕捉和回放以及二次開發(fā)提供了強有力的支持。 本系統(tǒng)采用 DirectShow 網 絡組播技術實現(xiàn)了視頻捕獲、視頻壓縮、網絡傳輸、視頻解碼和實時回放,減小了網絡帶寬占用,高效的傳輸視頻數(shù)據(jù),獨立于硬件。監(jiān)控服務器通過 Inter/Intra 輪詢網絡攝像機獲取視頻。用戶為了傳輸一個文件請求一個和其它計算機的連接,連接 建立后,就開始傳輸文件。 面向連接的 c/s時序圖如圖 41所示 服務器 客戶端 客戶端 . . . 5 圖 41 程序時序圖 系統(tǒng)由服務器終端采集傳輸系統(tǒng)和客戶端接收系統(tǒng)兩部分組,系統(tǒng)構架如圖 42所示 圖 42 系統(tǒng)架構 程序設計分析 Accept() Recv() Send() Close() Listen() Bind() Socket() 服務器 發(fā)送數(shù)據(jù) 確認發(fā)送數(shù)據(jù) 請求建立連接 Recv() Close() Send() Connect() Socket() 客戶 攝像頭 采集卡 服務器服務程序 網絡傳輸模塊 網絡接收模塊 客戶端程序 解碼 顯示 視頻流 控制指令 視頻流 控制指令 6 任務目標 服務器端程序目標:服務器服務器端服務程序進行數(shù)據(jù)采集(捕捉攝像頭捕獲數(shù)據(jù)),提供IP端口實現(xiàn)數(shù)據(jù)流的傳輸。 endregion // Return an array of the ip addresses assigned to this pc public static IPAddress [] GetAddresses() { IPAddress [] aryLocalAddr = null。 ()。 public event TcpConnected Disconnected。 if (bSend) (b, iLength, )。 ( , 0, , , receiveData, s )。 } WebCamService 類 : namespace WebCamService { public class WebCamService : ServiceBase { region Required Service Related Methods private ponents = null。 endregion /// summary /// Set things in motion so your service can do its work. /// 為了服務器可以工作而設置的選項 /// /summary protected override void OnStart(string[] args) { ThreadStart starter = new ThreadStart(Run)。 try { // Set up member vars ConnectionReady = new ManualResetEvent(false)。 } catch(Exception ex) { try { (({0}: Failed on startup {1}, (), ex))。 // Send the length as a fixed length string //作為固定的字符串長度發(fā)送長度 = 0。 20 m_PacketCount = 0。 ()。 23 private txtPort。 = new ()。 = 。 = new (19, 236)。 = new (10, 374)。 = Start。 (()()).BeginInit()。 public Form1() { // // Required for Windows Form Designer support // InitializeComponent()。 j 。 } public void RemovePacket() { lock (this) { if (m_PacketCount 0) { m_PacketCount。 } catch(Exception ex) { try { (())。 IntPtr ip = 。 += new TcpReceive(Receive)。 // zero based index of video capture device to use const int FRAMERATE = 15。 } endregion [STAThread] public static void Main(string[] args) { = Main thread。 } catch {} // Fire the Disconnected event if (Disconnected != null) Disconnected(this, ref )。 // Set up an async wait for packets from the client AsyncCallback receiveData = new AsyncCallback( OnReceivedData )。 // Create the listener socket in this machine39。 m_sockListener = null。 // Verify we