小编use*_*098的帖子

如何在多线程c#中使用TCP客户端/监听器?

我已经为我的服务器编写了这段代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    using System.Threading;
    using System.Net.Sockets;
    using System.IO;


namespace ConsoleApplication1
{
    class Program
    {
        private static bool terminate;

        public static bool Terminate
        {
            get { return terminate; }
        }

        private static int clientNumber = 0;
        private static TcpListener tcpListener;

        static void Main(string[] args)
        {
            StartServer();
            Console.Read();
        }

        private static void StartServer()
        {
            try
            {
                Console.WriteLine("Server starting...");
                tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8000);
                terminate = false;
                tcpListener.Start();
                tcpListener.BeginAcceptTcpClient(ConnectionHandler, null);
                Console.ReadLine();

            } …
Run Code Online (Sandbox Code Playgroud)

c# network-programming tcp tcplistener tcpclient

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

network-programming ×1

tcp ×1

tcpclient ×1

tcplistener ×1