簡介
TCP 是一個連線導向的網路傳輸協定,程式通常在斷線之前會一直記住這個連線。在我們使用 Socket 函式庫設計 TCP 網路程式時,通常會讓一個 Thread 負責處理一條連線,這樣可以讓問題變得較為單純,因為不需要用表格去記住連線。
所以,在學習 TCP 程式設計之前,我們有必要先複習一下 Thread (台灣稱為執行緒、中國大陸稱為線程) 的程式設計方式,若讀者對 Thread 尚不熟悉,請讀者先看完下列兩篇文章後再回到此處閱讀。
TCP 是一個連線導向的網路傳輸協定,程式通常在斷線之前會一直記住這個連線。在我們使用 Socket 函式庫設計 TCP 網路程式時,通常會讓一個 Thread 負責處理一條連線,這樣可以讓問題變得較為單純,因為不需要用表格去記住連線。
所以,在學習 TCP 程式設計之前,我們有必要先複習一下 Thread (台灣稱為執行緒、中國大陸稱為線程) 的程式設計方式,若讀者對 Thread 尚不熟悉,請讀者先看完下列兩篇文章後再回到此處閱讀。
UDP 是網路程式設計當中,最簡單的一種模式。本文將介紹如何使用 C# 撰寫 UDP 的『傳送-接收程式』。
使用 UDP 方式傳送訊息,由於封包是以一個一個的方式分別傳輸,先傳送者不一定會先到,甚至於沒有到達也不進行處理。由於這種方式不是連線導向的方式,因此不需要記住連線的 Socket,只要直接用 Socket 當中的 ReceiveFrom(data, ref Remote) 函數即可。
IP 是 TCP/IP 架構當中代表網址的層次,在撰寫 C# 網路程式時,幾乎每個程式都會用到 IP 層的物件,像是 IPAddress,IPEndPoint 等。我們將在本文當中介紹這些物件的使用方式。
IPAddress 物件代表一個 IP 網址,像是 210.59.154.30 就是一個 IP。在一個大機構當中,由於有自身的內部網路,因此 IP 通常也分為對內與對外兩種。舉例而言,筆者在金門技術學院電腦的內部 IP 是 192.168.60.155,外部 IP 是 210.59.154.30。學校內部的電腦可以透過內部 IP 192.168.60.155 連接到該電腦,但是校外的電腦就只能透過外部 IP 210.59.154.30 連結到該電腦。
最常被使用的網路函式庫稱為 Socket,這個名詞起源於柏克萊大學於 1983 年所釋放出來的 Berkeley Sockets 函式庫,該函式庫將網路視為串流。因而使存取網路的動作,與存取檔案一樣,都可以透過串流機制運行。
雖然 Socket 函式庫將網路抽像化為串流,但是理解網路的架構對程式的學習仍有很大的幫助,目前我們所使用的 Internet 網路是基於 TCP/IP 的網路架構,要能理解目前的網路程式架構,首先要從 TCP/IP 的架構下手。
System.Drawing.Bitmap img1 = new System.Drawing.Bitmap(@"C:/pic/original.jpg");
System.Drawing.Bitmap img2 = new System.Drawing.Bitmap(img1.Width *2, img1.Height*2 );
using System.Media
SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
simpleSound.Play();
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s = a.GetManifestResourceStream("<AssemblyName>.chimes.wav");
SoundPlayer player = new SoundPlayer(s);
player.Play();
This experimental code shows how to use DirectShow with .NET and C#. This includes simple media playback, playing DVD discs, capturing video streams to disk and a sample picture grabber.
Note, this article doesn't save you from reading the detailed DirectShow SDK documentation! I will not explain DirectShow, only some of the used .NET Interop technologies!
private void btnAddFrame_Click(object sender, EventArgs e) {
String tempFileName = System.IO.Path.GetTempFileName() + ".avi";
AviManager tempFile = new AviManager(tempFileName, false);
Bitmap bitmap = (Bitmap)Image.FromFile(txtNewFrameFileName.Lines[0].Trim());
tempFile.AddVideoStream(false, 1, bitmap);
VideoStream stream = tempFile.GetVideoStream();
for (int n = 1; n < txtNewFrameFileName.Lines.Length; n++) {
if (txtNewFrameFileName.Lines[n].Trim().Length > 0) {
stream.AddFrame((Bitmap)Image.FromFile(txtNewFrameFileName.Lines[n]));
}
}
editableStream.Paste(stream, 0, (int)numPastePositionBitmap.Value, stream.CountFrames);
tempFile.Close();
try { File.Delete(tempFileName); } catch (IOException) { }
}
陳鍾誠 (2011年12月27日),(網頁標題) 如何建立 AVI 檔案,(網站標題) 免費電子書:C# 程式設計,2011年12月27日,取自 http://cs0.wikidot.com/avi ,網頁修改第 0 版。
用 ListView 顯示資料夾內容
I'd like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView.
A cursor in Windows is an icon that is displayed when you move a mouse, a pen, or a trackball. Usually, a different cursor image is displayed for different activity. For instance, the default cursor is different than a wait cursor.
Cursors may be different for different operating systems. Figure 1 displays some of the cursors available on machine loaded with Windows 7 operating system. As you can presume from Figure 1, the Default cursor is loaded most of the time, the AppStarting cursor is displayed when any application is starting and loading, and the Size cursors are loaded when you are resizing an application.
This question has been asked for other languages, and even for those other languages, I have found their answers lacking in how to exactly do it, cleanly (no messed up screen repaints, etc..).
Is it possible to draw onto the Windows Desktop from C#? I am looking for an example if possible.
I have a .NET 3.5 project in VS 2010. Is there a way to convert the VS 2010 .csproj file format to a VS 2008 .csproj file format without making a new project using VS 2008 and re-adding everything? A tool or utility? Visual Studio, as far as I know, only provides an upgrade path.
I'm distributing the app source to users of VS 2008.
Almost all applications on your server, desktop, laptop or mobile device store data in the form of mass data, e.g. photos, binary files or documents and as meta data objects (key,value-pairs), e.g. blog entries, address records or geographical location information. Existing cloud services offer different interfaces for application integration to achieve nearly the same: to store mass and meta data in the cloud. SharpBox abstracts existing proprietary technologies under a clear, easy to use and reliable API available on the most important platforms in the industry (Windows, Linux, MAC, Windows Phone 7, Android and iOS).
Do you want to write code for storing data in the cloud only once in your application? SharpBox is the right free open source solution for your project. Our goal is to disburden software projects from the demand to implement storage access twice to support a wide range of storage clouds.
WebKit .NET is a WinForms control library wrapper for WebKit written in C#. The aim is to make it easy for developers to incorporate WebKit into their .NET applications.
For more information please visit the links to the left or the project homepage on SourceForge.
來源文件:Stackoverflow:Can I detect errors while using a .Net WebBrowser control?
The WebBrowser windows forms control is wrapper around Internet Explorer and it doesn't expose all the functionality of the underlying ActiveX control and particularly the NavigateError event. Here's a workaround:
參考:
var appName = Process.GetCurrentProcess().MainModule.ModuleName;
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", appName, 9999, RegistryValueKind.DWord);
InitializeComponent();