예제 #1
0
        /// <summary>
        /// Function to start the SocketServer
        /// </summary>
        /// <param name="ipAddress"> The IpAddress to listening on </param>
        /// <param name="port"> The Port to listen on </param>
        /// <param name="sizeOfRawBuffer"> Size of the Raw Buffer </param>
        /// <param name="userArg"> User supplied arguments </param>
        /// <param name="messageHandler"> Function pointer to the user MessageHandler function </param>
        /// <param name="acceptHandler"> Function pointer to the user AcceptHandler function </param>
        /// <param name="closeHandler"> Function pointer to the user CloseHandler function </param>
        /// <param name="errorHandler"> Function pointer to the user ErrorHandler function </param>
        public void Start(string ipAddress, int port, int sizeOfRawBuffer, object userArg,
                          MessageHandler messageHandler, AcceptHandler acceptHandler, CloseHandler closeHandler,
                          ErrorHandler errorHandler)
        {
            // Is an AcceptThread currently running
            if (this.acceptThread == null)
            {
                // Set connection values
                this.IpAddress = ipAddress;
                this.Port      = port;

                // Save the Handler Functions
                this.messageHandler = messageHandler;
                this.acceptHandler  = acceptHandler;
                this.closeHandler   = closeHandler;
                this.errorHandler   = errorHandler;

                // Save the buffer size and user arguments
                this.SizeOfRawBuffer = sizeOfRawBuffer;
                this.UserArg         = userArg;

                // Start the listening thread if one is currently not running
                ThreadStart tsThread = new ThreadStart(AcceptThread);
                this.acceptThread      = new Thread(tsThread);
                this.acceptThread.Name = "Notification.Accept";
                this.acceptThread.Start();
            }
        }
예제 #2
0
        /// <summary>
        /// Function to stop the SocketServer.  It can be restarted with Start
        /// </summary>
        public void Stop()
        {
            // Abort the accept thread
            if (this.acceptThread != null)
            {
                this.tcpListener.Stop();
                this.acceptThread.Join();
                this.acceptThread = null;
            }

            // Dispose of all of the socket connections
            for (int iSocket = 0; iSocket < this.socketClientList.Count; ++iSocket)
            {
                SocketClient socket = (SocketClient)socketClientList[iSocket];
                socketClientList.Remove(socket);
                socket.Dispose();
            }

            // Wait for all of the socket client objects to be destroyed
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // Clear the Handler Functions
            this.messageHandler = null;
            this.acceptHandler  = null;
            this.closeHandler   = null;
            this.errorHandler   = null;

            // Clear the buffer size and user arguments
            this.sizeOfRawBuffer = 0;
            this.userArg         = null;
        }
 public TcpPortHandler(int port, ITcpSetting setting, DataHandler handlerDelegate, ExceptionHandler errorHandler = null, AcceptHandler acceptDelegate = null, ZeroHandler zeroHandler = null)
 {
     _setting                  = setting;
     _port                     = port;
     _zeroHandlerDelegate      = zeroHandler;
     _exceptionHandlerDelegate = errorHandler;
     _handlerDelegate          = handlerDelegate;
     _acceptDelegate           = acceptDelegate;
 }
 public SocketListener(string listenerIP, int listenerPort, MessageHandler mh, CloseHandler ch, ErrorHandler eh, AcceptHandler ah, int bufferSize, int currentClients)
 {
     this.listenerIp = listenerIP;
     this.listenerPort = listenerPort;
     errorHandler = eh;
     acceptHandler = ah;
     listener = null;
     accept = null;
     disposed = false;
     criticalSection = new Object();
     this.currentClients = currentClients;
     this.bufferSize = bufferSize;
 }
예제 #5
0
파일: Logic.cs 프로젝트: MrBadge/Transport
        public MainLogic(Logger LogManager)
        {
            autodromeStreams   = new Dictionary <ulong, StreamInfo>();
            navigationStreams  = new List <StreamInfo>();
            applicationStreams = new List <StreamInfo>();
            output_buffer      = new byte[3000];

            acceptHandler = accept;
            errorHandler  = error;
            readHandler   = read;
            //availableHandler = new EventHandler(availabilityTimer_Tick);

            this.LogManager = LogManager;
        }
        private void Dispose()
        {
            if (!disposed) {
                if (accept != null)
                    Stop();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                acceptHandler = null;
                errorHandler = null;
                messageHandler = null;
                closeHandler = null;

                disposed = true;
            }
        }
예제 #7
0
 public Listener()
 {
     AcceptCallback = null;
 }
예제 #8
0
		/// <summary> 
		/// Function to stop the SocketServer.  It can be restarted with Start 
		/// </summary>
		public void Stop()
		{
			// Abort the accept thread
			if (this.acceptThread != null)
			{
				this.tcpListener.Stop();
				this.acceptThread.Join();
				this.acceptThread = null;
			}
    
			// Dispose of all of the socket connections
			for (int iSocket = 0; iSocket < this.socketClientList.Count; ++iSocket)
			{
				SocketClient socket = (SocketClient)socketClientList[iSocket];
				socketClientList.Remove( socket );
				socket.Dispose();
			}
      
			// Wait for all of the socket client objects to be destroyed
			GC.Collect();
			GC.WaitForPendingFinalizers();
      
			// Clear the Handler Functions
			this.messageHandler = null;
			this.acceptHandler  = null;
			this.closeHandler   = null;
			this.errorHandler   = null;
      
			// Clear the buffer size and user arguments
			this.sizeOfRawBuffer = 0;
			this.userArg = null;
		}
예제 #9
0
		/// <summary> 
		/// Function to start the SocketServer 
		/// </summary>
		/// <param name="ipAddress"> The IpAddress to listening on </param>
		/// <param name="port"> The Port to listen on </param>
		/// <param name="sizeOfRawBuffer"> Size of the Raw Buffer </param>
		/// <param name="userArg"> User supplied arguments </param>
		/// <param name="messageHandler"> Function pointer to the user MessageHandler function </param>
		/// <param name="acceptHandler"> Function pointer to the user AcceptHandler function </param>
		/// <param name="closeHandler"> Function pointer to the user CloseHandler function </param>
		/// <param name="errorHandler"> Function pointer to the user ErrorHandler function </param>
		public void Start(string ipAddress, int port, int sizeOfRawBuffer, object userArg,
			MessageHandler messageHandler, AcceptHandler acceptHandler, CloseHandler closeHandler, 
			ErrorHandler errorHandler)
		{
			// Is an AcceptThread currently running
			if (this.acceptThread == null)
			{
				// Set connection values
				this.IpAddress = ipAddress;
				this.Port = port;
        
				// Save the Handler Functions
				this.messageHandler = messageHandler;
				this.acceptHandler = acceptHandler;
				this.closeHandler = closeHandler;
				this.errorHandler = errorHandler;
        
				// Save the buffer size and user arguments
				this.SizeOfRawBuffer = sizeOfRawBuffer;
				this.UserArg = userArg;
        
				// Start the listening thread if one is currently not running
				ThreadStart tsThread = new ThreadStart(AcceptThread);
				this.acceptThread = new Thread(tsThread);
				this.acceptThread.Name = "Notification.Accept";
				this.acceptThread.Start();
			}
		}