使用netty4.x 編寫TCP服務器關於握手問題

仍是和機頂盒通信的項目,netty編寫udp的協議已經實現了完畢;
shell

要求TCP也要來一套....我就呵呵了...寫唄.服務器

基本上流程差很少,decoder,encoder,handler幾乎均可以重用的,寫好後一測..嚇我一大蹦oop

[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x2264fc80, /192.168.1.108:50671 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0xe19dd5d6, /192.168.1.108:50672 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x0c6528da, /192.168.1.108:50673 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x627a3d1b, /192.168.1.108:50674 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x38ca0152, /192.168.1.108:50675 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0xd423fe93, /192.168.1.108:50676 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x978e3190, /192.168.1.108:50677 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0xcb219784, /192.168.1.108:50678 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x205d58c1, /192.168.1.108:50679 => /192.168.1.120:5000]
2015-07-25 17:29:45
[INFO]-[Thread: nioEventLoopGroup-3-1]-[io.netty.util.internal.logging.Slf4JLogger.info()]: [id: 0x0bdcf37c, /0:0:0:0:0:0:0:0:5000] RECEIVED: [id: 0x3ba890f4, /192.168.1.108:50680 => /192.168.1.120:5000]
2015-07-25 17:29:45


服務器啓動,客戶端訪問後,控制檯瞬間打印出一大堆日誌,又沒有異常...客戶端在進行批量鏈接,要不是本身寫的還覺得是攻擊呢..net

仔細想了想好像沒有地方出紕漏,開了wireshark抓了下包,如圖:3d

server 192.168.1.120:5000日誌

remote 192.168.1.108:50404netty

這是一次完整的請求,順序依次是(3次握手->數據傳輸->握手關閉),關閉是服務器主動提出的的(5000->50404)發送的FIN包,很是奇怪,代碼中並無主動關閉鏈接的地方..code

檢查代碼發現,decoder中解碼時由於"\r\n"未處理,提取協議數據時出現異常,異常呢??..由於控制檯刷的太快..直接刷過了...server

相關文章
相關標籤/搜索