返回顶部

收藏

C# 一个最简单的 TCP 通讯的客户端例子

更多
using System;
using System.IO;
using System.Net.Sockets;

public class NetWriter {
  public static void Main(string [] args) {

    string address = "outofmemory.cn
    int port = 80;

    TcpClient client = new TcpClient(address,port);
    NetworkStream stream = client.GetStream( );

    StreamWriter writer = new StreamWriter(stream);

    writer.WriteLine("outofmemory.cn
    writer.Flush( );

    using (StreamReader reader = new StreamReader(stream)) {
      while (reader.Peek( ) != -1) {
        Console.WriteLine(reader.ReadLine( ));
      }
    }
  }
}
//该片段来自于http://outofmemory.cn

标签:c#,.net,网络

收藏

0人收藏

支持

0

反对

0

发表评论