NioSocket簡(jiǎn)單復(fù)習(xí)
重要概念
NioSocket里面的三個(gè)重要概念:Buffer、Channel、Selector
使用步驟
使用NioSocket實(shí)現(xiàn)通信大概如以下步驟:
實(shí)現(xiàn)HTTP
創(chuàng)建HttpServer類作為程序的主要入口
public class HttpServer { public static void main(String[] args) throws Exception{ ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress((8080))); serverSocketChannel.configureBlocking(false); Selector selector = Selector.open(); // It must be ACCEPT, or it will throw exception serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); while(true){ if (selector.select(3000) == 0){ continue; } Iterator<SelectionKey> keyIter = selector.selectedKeys().iterator(); while (keyIter.hasNext()){ SelectionKey key = keyIter.next(); new Thread(new HttpHandler(key)).run(); keyIter.remove(); } } } }
文章題目:Java使用NioSocket手動(dòng)實(shí)現(xiàn)HTTP服務(wù)器-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://sd-ha.com/article46/dpcihg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站營(yíng)銷、品牌網(wǎng)站制作、品牌網(wǎng)站設(shè)計(jì)、軟件開(kāi)發(fā)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
網(wǎng)頁(yè)設(shè)計(jì)公司知識(shí)