Commits

Hector Miuler Malpica Gallegos  committed 2bf3561

Cambios:
* Al cerrar la aplicación qt, cierra el servidor mock smtp.
* Se agregó un mensaje al iniciar la conexión.

  • Participants
  • Parent commits 027df39
  • Tags pruebaChannelInboundByte

Comments (0)

Files changed (2)

File src/main/scala/com/miuler/mocksmtp/core/MockSMTP.scala

 import io.netty.channel._
 import io.netty.channel.socket.SocketChannel
 import io.netty.buffer.ByteBuf
-import io.netty.util.CharsetUtil
+import io.netty.buffer.Unpooled.copiedBuffer
 import io.netty.util.CharsetUtil.UTF_8
+import java.net.InetAddress
+import java.util.Date
 
-/**
- * Created with IntelliJ IDEA.
- * User: miuler
- * Date: 30/09/12
- * Time: 11:03 PM
- * To change this template use File | Settings | File Templates.
- */
+
 class MockSMTP {
 
   private val log = LoggerFactory.getLogger(classOf[MockSMTP])
   var server: ServerBootstrap = _
 
   def start = {
-
-    class ChannelInboundHandlerBasic extends ChannelInboundByteHandlerAdapter {
-      def inboundBufferUpdated(ctx: ChannelHandlerContext, in: ByteBuf) {
-        log.debug("mensage: \n{}", in.toString(UTF_8))
-        ctx.write(in)
-        in.clear()
-      }
-    }
-
-    log.debug("new server")
+    log.debug("start server")
     server = new ServerBootstrap()
       .group(new NioEventLoopGroup())
       .channel(classOf[NioServerSocketChannel])
   def stop = server.shutdown()
 
 }
+
+
+class ChannelInboundHandlerBasic extends ChannelInboundByteHandlerAdapter {
+
+  private val log = LoggerFactory.getLogger(classOf[MockSMTP])
+
+  override def channelActive(ctx: ChannelHandlerContext) {
+    log.debug("channelActive")
+    var msg = "220 ***************************************"
+    ctx.write(copiedBuffer(msg.toCharArray, UTF_8))
+    //ctx.fireChannelActive(); //TODO: I do not know if this is necessary
+  }
+
+  override def inboundBufferUpdated(ctx: ChannelHandlerContext, in: ByteBuf) {
+    log.debug("mensage: \n{}", in.toString(UTF_8))
+    ctx.write(in)
+    in.clear()
+
+  }
+}
+

File src/main/scala/com/miuler/mocksmtp/gui/MainGUI.scala

  * To change this template use File | Settings | File Templates.
  */
 class MainGUI(id: String = null, serverId: String = null) {
+  QApplication.initialize(Array())
+  new MainWindowSMTP()
+  QApplication.exec()
+}
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: miuler
+ * Date: 13/09/12
+ * Time: 08:16 PM
+ * To change this template use File | Settings | File Templates.
+ */
+class MainWindowSMTP(id: String = null, serverId: String = null) extends QWidget {
 
   private val log = LoggerFactory.getLogger(classOf[MainGUI])
 
   var btnStopSMTP: QPushButton = _
   val mockSMTP = new MockSMTP()
 
-  log.debug("MainGUI: Begin constructor")
-  QApplication.initialize(Array())
   initGUI
-  QApplication.exec()
-  log.debug("MainGUI: End constructor")
-
 
   private def initGUI {
     btnInitSMTP = new QPushButton()
     layout.addWidget(btnInitSMTP)
     layout.addWidget(btnStopSMTP)
 
-    val window = new QWidget()
-    window.setWindowTitle("MOCK SMTP")
-    window.setLayout(layout)
-    window.show()
+    setWindowTitle("MOCK SMTP")
+    setLayout(layout)
+    show()
   }
 
   def startSMTP() {
     }
   }
 
+  override def closeEvent(evn: QCloseEvent) {
+    log.debug("salir")
+    if (btnInitSMTP.isChecked()) {
+      log.debug("Apagando el servidor")
+      mockSMTP.stop
+    }
+  }
 }