/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example15_12b.cs implements a NetworkStream client
*/
using System;
using System.IO;
using System.Net.Sockets ;
public class Example15_12b
{
public static void Main()
{
// create a client socket
TcpClient newSocket = new TcpClient("localhost", 50001);
// create a NetworkStream to read from the host
NetworkStream ns = newSocket.GetStream();
// fill a byte array from the stream
byte[] buf = new byte[100];
ns.Read(buf, 0, 100);
// convert to a char array and print
char[] buf2 = new char[100];
for(int i=0;i<100;i++)
buf2[i]=(char)buf[i];
Console.WriteLine(buf2);
// clean up
ns.Close();
newSocket.Close();
}
}