2017-08-03 58 views
0

我試圖從netSocketClient收到聯合國文件中vetrx 3.4.2文件,這是我的代碼:Vertx 3.4.2接收使用netSocket

NetServerOptions options = new NetServerOptions().setPort(10000); 
NetServer netserver = vertx.createNetServer(options); 
netserver.connectHandler(sock -> { 

    System.out.println("Incoming connection!"); 
    sock.handler(buffer-> { 
     String dd = buffer.getString(0,buffer.length()); 
     System.out.println("new Buffer: "+dd); 
     sock.write("From serveur: "+buffer.getString(0, buffer.length())); 
    }); 

    sock.closeHandler(v -> { 
     System.out.println("The socket has been closed"); 
    }); 
}).listen(); 

,但我收到decoped緩衝區。

我的問題是我如何可以在單個緩衝區中獲取文件的結束緩衝區?

有人可以幫我嗎?

回答

0

我試試這個,它的工作:

StringBuffer buff = new StringBuffer(); 
sock.handler(buffer-> { 
    String dd = buffer.getString(0,buffer.length()); 
    if(dd.contains("EOT")){ 
     dd = dd.replace("EOT", ""); 
     buff.append(dd); 
    }else{ 
     buff.append(dd); 
    } 
});