简体   繁体   中英

thread safety of concurrent read and write on a socket

A tcp socket is an endpoint which has bidirectional read and write capabilities. In java we can aquire InputStream and OutputStream of the Socket.

is it safe to use those streams concurrently?

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.

I'm implementing nio transport layer based on SocketChannels, and i want to keep one thread for all writes and one thread for accepting and reads, but i'm not sure what will happen if my threads concurrently try to read and write at the same time on the same socket...

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.

Or both at the same time. It's a full-duplex connection. You can send and receive at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM