- using System;
- using System.IO;
- using System.Net.Sockets;
- public class NetWriter {
- public static void Main(string [] args) {
- string address = "www.oschina.net";
- int port = 80;
- TcpClient client = new TcpClient(address,port);
- NetworkStream stream = client.GetStream( );
- StreamWriter writer = new StreamWriter(stream);
- writer.WriteLine("www.oschina.net\\n");
- writer.Flush( );
- using (StreamReader reader = new StreamReader(stream)) {
- while (reader.Peek( ) != -1) {
- Console.WriteLine(reader.ReadLine( ));
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2503201511974.html
来源: http://www.codesnippet.cn/detail/2503201511974.html