while (true)
{
string message = Console.ReadLine();
Byte[] data = Encoding.UTF8.GetBytes(message);
clienSocket.Send(data);
Byte[] data2 = new byte[1024];
int lenght = clienSocket.Receive(data2);
string message2 = Encoding.UTF8.GetString(data2, 0, lenght);
Console.WriteLine(“接受到一条数据” + message2);
}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace TCP_客户端
{
class Program
{
static void Main(string[] args)
{
byte[] data;
string message;
Socket clienSocket = new Socket(AddressFamily.InterNetwork,SocketType.