Beispiel #1
0
 /// <summary>
 /// Allow data to be read from clients
 /// </summary>
 public override void StartListening()
 {
     try
     {
         serverClosed = false;
         TcpListener serverSocket = new TcpListener(IPAddress.Any, m_port);
         TcpClient   clientSocket = default(TcpClient);
         serverSocket.Start();
         new Thread(() =>
         {
             try
             {
                 for (int i = 0; i < MaximumIncomingConnections && !serverClosed; i++)
                 {
                     clientSocket = serverSocket.AcceptTcpClient();
                     ThreadPool.QueueUserWorkItem(ServerThread, new ServerStartInfo(null, clientSocket));
                     connectedClients.Add(clientSocket);
                 }
             }
             catch (Exception ex)
             {
                 OnListenStop?.Invoke(this, new ListenStopEventArgs("An error occures while trying to accept incoming data", ex));
             }
         }).Start();
         OnListenStart?.Invoke(this, ListenStartEventArgs.Empty);
     }
     catch (SocketException ex)
     {
         throw new Exception("Already listening. If you wish to listen on another port instantiate another object", ex);
     }
 }
Beispiel #2
0
 public void RemoveOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates -= del;
 }
Beispiel #3
0
 public void SetOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates = del;
 }
Beispiel #4
0
 public void AddOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates += del;
 }
 public void RemoveOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates -= del;
 }
 public void SetOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates = del;
 }
 public void AddOnListenStartDelegate(OnListenStart del)
 {
     this.OnListenStartDelegates += del;
 }