ServerSocketChannel 寫入數據

public class Test {
public static void main(String[] args) {
try {
ServerSocketChannel serverChannel = ServerSocketChannel.open();
serverChannel.socket().bind(new InetSocketAddress(8888));
ByteBuffer buf = ByteBuffer.allocateDirect(1024);
SocketChannel client = serverChannel.accept();

        while(true) {
            buf.put("get / /n/n".getBytes());
            buf.flip();
            client.write(buf);
            buf.clear();
            client.close();
        }
    } catch (Exception e){
        //logger.error("fail to create port 8888", e);
        e.printStackTrace();
    }


    String test = "a###b######c";
    String [] tt = org.apache.commons.lang3.StringUtils.splitByWholeSeparatorPreserveAllTokens(test, "###");
    System.out.println(tt.length);
    for (int i = 0; i< tt.length; i++){
        System.out.println(tt[i]);
    }
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章