using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MyTCPListener
{
class Program
{
const int nPort = 6262;
static void Main(string[] args)
{
Socket client = null;
Console.WriteLine("OK");
TcpListener tl = new TcpListener(nPort);
Console.WriteLine("Listening as {0}",tl.LocalEndpoint);
tl.Start();
do
{
if (tl.Pending())
{
client = tl.AcceptSocket();
DateTime now = DateTime.Now;
string welcome = "Welcome at " + now.ToString("G") + "\n\r";
Byte[] byteWelcome = System.Text.Encoding.ASCII.GetBytes(welcome);
client.Send(byteWelcome, byteWelcome.Length, 0);
}
} while (true);
}
}
}
C#同步socket例子
最新推荐文章于 2022-02-25 20:00:37 发布
2417

被折叠的 条评论
为什么被折叠?



