Пример #1
0
        public MessageReceiver(String ipAddress, int portNo, BaseReceiveHandler receiveHandler)
        {
            try
            {
                // 1. ACCEPTOR 생성
                this.acceptor = new AsyncSocketAcceptor();

                // 2. DEFINE FILTER
                // 2.1. Logger filter
                this.acceptor.FilterChain.AddLast("logger", new LoggingFilter());

                // 2.2. Codec filter
                ObjectSerializationCodecFactory objectSerializationCodecFactory = new ObjectSerializationCodecFactory();
                objectSerializationCodecFactory.DecoderMaxObjectSize = CommConst.MAX_TRANSDATA_SIZE;;
                this.acceptor.FilterChain.AddLast("codec", new ProtocolCodecFilter(objectSerializationCodecFactory));

                // 3. SET HANDLER
                this.acceptor.Handler = receiveHandler;

                // 4. BIND
                this.acceptor.Bind(new IPEndPoint(IPAddress.Any, portNo));

                Console.WriteLine("Listening on " + acceptor.LocalEndPoint);
            }
            catch (Exception ex)
            {
                throw new Exception("Message Receiver를 생성하지 못했습니다.", ex);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                //ReceiveHandlerEx receiveHandlerEx = new ReceiveHandlerEx();
                //IMessageReceiver msgReceiver = new MessageReceiver("127.0.0.1", CommConst.PORT, receiveHandlerEx);
                BaseReceiveHandler receiveHandler = new BaseReceiveHandler();
                IMessageReceiver   msgReceiver    = new MessageReceiver("127.0.0.1", CommConst.PORT, receiveHandler);

                Console.WriteLine("Runing EchoServer...");

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }