我不确定这个标题是否具有丰富的信息.
我正在尝试查找/编写一个套接字服务器,它将接受来自客户端(telnet)的连接,然后代表连接的客户端,连接到网络内的四个telnet服务器之一.
连接后,我会计算出有多少连接,然后如果有4个连接,则禁止任何新连接,直到四个连接中的一个可用.
我写了这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static int nodeCount = 4;
static int currentNode = 1;
static void Main(string[] args)
{
ServerProgram server = new ServerProgram();
}
class ServerProgram
{
private TcpListener tcpPrimaryListener;
private Thread listenThread;
public ServerProgram()
{
this.tcpPrimaryListener = new TcpListener(IPAddress.Any, 23);
Console.WriteLine("Telnet BBS Port Concentrator Server Started.");
Console.WriteLine("--------------------------------------------");
this.listenThread = new Thread(new ThreadStart(ListenForClients));
this.listenThread.Start();
}
private void …Run Code Online (Sandbox Code Playgroud)