大家帮我看看我的程序哪儿出错啦
在线等服务端
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IPAddress serverIP = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(serverIP,10000);
listener.Start();
while (true)
{
Socket s = listener.AcceptSocket();
byte[] recvBytes = new byte[256];
int bytes = 0;
while (true)
{
bytes = s.Receive(recvBytes, recvBytes.Length,0);
string recvString = Encoding.ASCII.GetString(recvBytes);
Console.WriteLine();
if (bytes == 0)
break;
}
}
}
}
}
客户端
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
TcpClient client = new TcpClient();
IPAddress serverIP = IPAddress.Parse("127.0.0.1");
client.Connect(serverIP, 10000);
NetworkStream stream = client.GetStream();
string sendString = "hello";
byte[] sendBytes = Encoding.ASCII.GetBytes(sendString.ToCharArray());
stream.Write(sendBytes,0,sendBytes.Length);
}
}
}