TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse(HOST_IP), HOST_PORT);
Stream stream = client.GetStream();
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
writer.AutoFlush = true;
while (true) {
string line;
while((line = reader.ReadLine())!=null) {
Console.WriteLine(line);
}
writer.WriteLine(Console.ReadLine());
}
我的服务器向客户端发送两个字符串:
var stream = new NetworkStream(soc);
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
writer.AutoFlush = true
writer.WriteLine("Welcome: ");
writer.WriteLine("Bla...: ");
reader.ReadLine();
我的客户会显示
Welcome
Bla..
但它不运行命令writer.WriteLine(Console.ReadLine());