안녕하세요 현재 socket 통신 관련 개발을 하고 있습니다.
server에 접근할 수 있는 client수를 5개로 제한 하고 싶은데 아무리 찾아도 모르겠고, 이해가 되지 않아 글을 남깁니다.
//Server Open
                    ServerSoc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    ServerSoc.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                    IPAddress ServerIP = IPAddress.Parse(strIP);
                    IPEndPoint IPEP = new IPEndPoint(ServerIP, iPort);
                    ServerSoc.Bind(IPEP);
                    ServerSoc.Listen(20);
                    //ServerSoc.Blocking = true;
                    SocketAsyncEventArgs Args = new SocketAsyncEventArgs();
                    Args.Completed += new EventHandler<SocketAsyncEventArgs>(ServerAccept);
                    ServerSoc.AcceptAsync(Args);
                    bConntReq = true;    //오픈 성공
                    bConnectOK = false;
//Client Accept
                    if (SocList.Count < 5)
                    {
                        SocList.Add(e.AcceptSocket);string strAddr = SocList[SocList.Count - 1].RemoteEndPoint.ToString();
                        string[] strArr = strAddr.Split(new char[] { ':' });
                        bConnectOK = true;
                        Log.LogStr(false, DataContainers.SYS, "ClientCount: " + (SocList.Count).ToString() + ", Client IP: " + strArr[0] + " Port: " + strArr[1] + ", Connect Success");
                        if (TCPIPThread == null)
                        {
                            TCPIPThread = new Thread(SendData);
                            bTCPIPThreadChk = true;
                            TCPIPThread.Start();
                            Log.LogStr(false, DataContainers.SYS, "TCPIPThread Start");
                        }
                    }
                    else
                        Log.LogStr(false, DataContainers.SYS, "ServerAccept, 연결 가능 Client 개수 초과, Client Count: " + SocList.Count.ToString());
                 
                    e.AcceptSocket = null;
                    ServerSoc.AcceptAsync(e);   //새로운 Client 대기
위와 같이 소스를 구현해뒀습니다. 
6번째 클라이언트가 접속 시 오픈되어있는 서버로 접속은 가능하지만, 데이터는 안들어 오도록 되어있습니다.
제가 하고 싶은건 아예 오픈되어있는 서버로 접속도 못하게끔 막는 것 입니다. 
1. 5번째 클라이언트가 들어왔을 때 서버를 close하는 방법 밖에는 없는 것인가요? 
100ms마다 계속해서 데이터를 전송해야 하는데 close를 시켜도 상관이 없을까요...?
                        if (SocList.Count == 1)
                        {
                            ServerSoc.Close();
                            bConntReq = false;
                        }
2. server socket을 닫는 방법 말고 막는 방법이 있다면 알려주세요..
답변 달아주시면 감사하겠습니다...!!
        
        
                    
                    
                    
                    
                    
    
                    
                    
                    
                    
                    
                
                    [최초 등록일: ]
                    [최종 수정일: 11/15/2018]