예제 #1
0
 private void CallMessageHandler(AdkSocketMessageHandler handler)
 {
     if (handler != null)
     {
         handler(this);
     }
 }
예제 #2
0
        /// <summary>
        /// Constructor for SocketServer Supppor
        /// </summary>
        /// <param name="server">A Reference to the parent SocketServer</param>
        /// <param name="wrappedSocket">RetType: The Socket object we are encapsulating</param>
        /// <param name="sizeOfRawBuffer">The size of the raw buffer</param>
        /// <param name="messageHandler">Reference to the user defined message handler function</param>
        /// <param name="closeHandler">Reference to the user defined close handler function</param>
        /// <param name="errorHandler">Reference to the user defined error handler function</param>
        public AdkSocketConnection(
            AdkSocketBinding server,
            IConnectedSocket wrappedSocket,
            int sizeOfRawBuffer,
            AdkSocketMessageHandler messageHandler,
            AdkSocketMessageHandler closeHandler,
            AdkSocketErrorHandler errorHandler
            )
        {
            // Create the raw buffer
            fRawBufferSize = sizeOfRawBuffer;
            fRawBuffer     = new Byte[sizeOfRawBuffer];

            // Set the handler functions
            fMessageHandler = messageHandler;
            fCloseHandler   = closeHandler;
            fErrorHandler   = errorHandler;

            // Set the async socket function handlers
            fReadCompleteCallback = new AsyncCallback(ReceiveComplete);

            // Set reference to SocketServer
            fSocketServer = server;

            // Init the socket references
            fWrappedSocket = wrappedSocket;

            // Init the NetworkStream reference
            fStream = fWrappedSocket.CreateStream(FileAccess.ReadWrite, false);

            // Set these socket options
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, sizeOfRawBuffer);
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sizeOfRawBuffer);
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1);
            fWrappedSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);

            // Wait for a message
            Receive();
        }
        /// <summary>
        /// Constructor for SocketServer Supppor
        /// </summary>
        /// <param name="server">A Reference to the parent SocketServer</param>
        /// <param name="wrappedSocket">RetType: The Socket object we are encapsulating</param>
        /// <param name="sizeOfRawBuffer">The size of the raw buffer</param>
        /// <param name="messageHandler">Reference to the user defined message handler function</param>
        /// <param name="closeHandler">Reference to the user defined close handler function</param>
        /// <param name="errorHandler">Reference to the user defined error handler function</param>
        public AdkSocketConnection(
            AdkSocketBinding server,
            IConnectedSocket wrappedSocket,
            int sizeOfRawBuffer,
            AdkSocketMessageHandler messageHandler,
            AdkSocketMessageHandler closeHandler,
            AdkSocketErrorHandler errorHandler
            )
        {
            // Create the raw buffer
            fRawBufferSize = sizeOfRawBuffer;
            fRawBuffer = new Byte[sizeOfRawBuffer];

            // Set the handler functions
            fMessageHandler = messageHandler;
            fCloseHandler = closeHandler;
            fErrorHandler = errorHandler;

            // Set the async socket function handlers
            fReadCompleteCallback = new AsyncCallback( ReceiveComplete );

            // Set reference to SocketServer
            fSocketServer = server;

            // Init the socket references
            fWrappedSocket = wrappedSocket;

            // Init the NetworkStream reference
            fStream = fWrappedSocket.CreateStream( FileAccess.ReadWrite, false );

            // Set these socket options
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, sizeOfRawBuffer );
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sizeOfRawBuffer );
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1 );
            fWrappedSocket.SetSocketOption( SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1 );

            // Wait for a message
            Receive();
        }
 private void CallMessageHandler( AdkSocketMessageHandler handler )
 {
     if ( handler != null ) {
         handler( this );
     }
 }