using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
namespace tcp网络传输服务器
{
class Program
{
static void Main(string[] args)
{
bool done = false;
TcpListener listener = new TcpListener(13);
listener.Start();
while (!done)
{
Console.Write("waitting for connection....");
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("connection accepted");
NetworkStream ns = client.GetStream();
byte[] byteTime = Encoding.ASCII.GetBytes(DateTime.Now.ToString());
try
{
ns.Write(byteTime, 0, byteTime.Length);
ns.Close();
client.Close();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
listener.Stop();
}
}
}