ex-21-09
来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 60 行
TXT
60 行
// 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 + =
减小字号Ctrl + -
显示快捷键?