VS制作简易的服务器

本文介绍了如何使用Visual Studio(VS)创建一个简单的多人聊天服务器。通过新建控制台应用程序,利用TcpListener监听客户端连接,实现聊天大厅功能。当有新的客户端接入时,服务器将接收并分发消息,支持群发文本到所有在线客户端。
摘要由CSDN通过智能技术生成

今天我们来看一个制作多人聊天的工程,首先打开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()
        {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值