📄 ex-21-09
字号:
// Example 21-09: Implementing a network streaming client
using System;
using System.Net.Sockets;
public class Client
{
static public void Main( string[] Args )
{
// create a TcpClient to talk to the server
TcpClient socketForServer;
try
{
socketForServer =
new TcpClient("localHost", 65000);
}
catch
{
Console.WriteLine(
"Failed to connect to server at {0}:65000",
"localhost");
return;
}
// create the Network Stream and the Stream Reader object
NetworkStream networkStream =
socketForServer.GetStream();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(networkStream);
try
{
string outputString;
// read the data from the host and display it
do
{
outputString = streamReader.ReadLine();
if( outputString != null )
{
Console.WriteLine(outputString);
}
}
while( outputString != null );
}
catch
{
Console.WriteLine(
"Exception reading from Server");
}
// tidy up
networkStream.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -