套接字上并发读写的线程安全
thread safety of concurrent read and write on a socket
TCP 套接字是具有双向读写能力的端点。在java我们可以获取到Socket的InputStream和OutputStream。
同时使用这些流是否安全?
据我所知,有一个连接能够在任何给定时间从一个端点向其他数据发送或接收数据。
我正在基于 SocketChannels 实现 nio 传输层,我想为所有写入保留一个线程,为接受和读取保留一个线程,但我不确定如果我的线程同时尝试读取会发生什么并同时写入同一个套接字...
As far as I know there is a single connection that is capable to send or recieve from one endpoint to other data at any given time.
或两者同时。这是一个全双工连接。您可以同时发送和接收。
TCP 套接字是具有双向读写能力的端点。在java我们可以获取到Socket的InputStream和OutputStream。
同时使用这些流是否安全?
据我所知,有一个连接能够在任何给定时间从一个端点向其他数据发送或接收数据。
我正在基于 SocketChannels 实现 nio 传输层,我想为所有写入保留一个线程,为接受和读取保留一个线程,但我不确定如果我的线程同时尝试读取会发生什么并同时写入同一个套接字...
As far as I know there is a single connection that is capable to send or recieve from one endpoint to other data at any given time.
或两者同时。这是一个全双工连接。您可以同时发送和接收。