【说站】java中SocketChannel是什么
2024-10-09
16
java中SocketChannel是什么
1、说明
SocketChannel代表套接字通道,实例是通过其静态方法创建的。
SocketChannel是SelectableChannel的子类,假如没有配置阻塞模式,那么SocketChannel对象默认为阻塞模式,那么open(SocketAddressremote)的方法实际上就是阻塞打开服务器连接。而SocketChannel上的任何I/O操作都是阻塞的。
2、实例
public static SocketChannel open() throws IOException { return SelectorProvider.provider().openSocketChannel(); } public static SocketChannel open(SocketAddress remote) throws IOException { // 1. ceate socket channel SocketChannel sc = open(); try { // 2. connect channel's socket, blocking until connected or error sc.connect(remote); } catch (Throwable x) { try { sc.close(); } catch (Throwable suppressed) { x.addSuppressed(suppressed); } throw x; } assert sc.isConnected(); return sc; }
以上就是java中SocketChannel的介绍,希望对大家有所帮助。更多Java学习指路:Java基础
本教程操作环境:windows7系统、java10版,DELL G3电脑。
更新于:9天前赞一波!
相关文章
- 【说站】java语言的发展历史
- 【说站】java语言的特点有哪些
- 【说站】java语言属于哪种语言
- 【说站】java语言代码大全
- 【说站】java和c 哪个好
- 【说站】java语言好还是c 好
- 【说站】新手学c还是java
- 【说站】java与c语言区别
- 【说站】java反射三种方法
- 【说站】Java泛型中有几种通配符
- 【说站】Java如何创建类型实例
- 【说站】Java泛型擦除的问题解决
- 【说站】SocketChannel在java中实现客户端
- 【说站】java中Selector如何选择通道
- 【说站】java泛型接口怎么用
- 【说站】java泛型方法的使用注意
- 【说站】Java泛型类如何定义
- 【说站】Java泛型擦除的原理分析
- 【说站】java泛型方法的特征
- java 安全沙箱模型详解
文章评论
评论问答