日期:2014-05-18 浏览次数:21006 次
using System; using System.IO; using System.Net.Sockets; using System.Net; class Example { static void Main() { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress hostAddress = Dns.GetHostEntry("localhost").AddressList[0]; s.Connect(hostAddress, 8000); NetworkStream ns = new NetworkStream(s); StreamReader sr = new StreamReader(ns); char[] buffer=new char[5]; sr.Read(buffer, 0, 1); StreamWriter sw = new StreamWriter(ns); sw.Write(true); sw.Close(); sr.Close(); ns.Close(); } }