當前位置: 首頁>>代碼示例>>C#>>正文


C# NetworkStream.ReadTimeout屬性代碼示例

本文整理匯總了C#中System.Net.Sockets.NetworkStream.ReadTimeout屬性的典型用法代碼示例。如果您正苦於以下問題:C# NetworkStream.ReadTimeout屬性的具體用法?C# NetworkStream.ReadTimeout怎麽用?C# NetworkStream.ReadTimeout使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在System.Net.Sockets.NetworkStream的用法示例。


在下文中一共展示了NetworkStream.ReadTimeout屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TcpClient

// Create a client that will connect to a 
// server listening on the contosoServer computer
// at port 11000.
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("contosoServer", 11000);
// Get the stream used to read the message sent by the server.
NetworkStream networkStream = tcpClient.GetStream();
// Set a 10 millisecond timeout for reading.
networkStream.ReadTimeout = 10;
// Read the server message into a byte buffer.
byte[] bytes = new byte[1024];
networkStream.Read(bytes, 0, 1024);
//Convert the server's message into a string and display it.
string data = Encoding.UTF8.GetString(bytes);
Console.WriteLine("Server sent message: {0}", data);
networkStream.Close();
tcpClient.Close();
開發者ID:.NET開發者,項目名稱:System.Net.Sockets,代碼行數:17,代碼來源:NetworkStream.ReadTimeout


注:本文中的System.Net.Sockets.NetworkStream.ReadTimeout屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。