今天我们来看一个制作多人聊天的工程,首先打开VS新建一个控制台应用程序,编写脚本
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Threading;
/// <summary>
/// 聊天大厅
/// </summary>
namespace LessonChat
{
class Program
{
//创建保存多个虚拟客户端对象的链表
public List<MyClient> AllClient = new List<MyClient>();
static void Main(string[] args)
{
Program pro = new Program();
pro.Start();
}
TcpListener tcpListener;
public void Start()
{
tcpListener = new TcpListener(IPAddress.Parse("192.168.10.235"),2333);
//挂起队列的最大长度
tcpListener.Start(100);
Thread thread = new Thread(ListenerServerThread);
thread.Start();
Console.WriteLine(tcpListener.Pending());
}
//线程->检测客户端有没有接入
public void ListenerServerThread()
{