简体   繁体   English

java socket全双工

[英]java socket full duplex

Is it possible to have a server and a client with 1 socket connection and send data in both directions at the same time? 是否可以让服务器和客户端具有1个套接字连接,并同时向两个方向发送数据? I mean both the server and the client reads and writes on the same time (2 threads in each process) 我的意思是服务器和客户端同时读写(每个进程中有2个线程)

Edit: I need "true" two-way communications and not the request / response kind of communication. 编辑:我需要“真正的”双向通信,而不是请求/响应类型的通信。 Both the client and the server must be able to write at the same time. 客户端和服务器都必须能够同时写入。

Edit2: God Dame! 编辑2:上帝圣母! It works. 有用。 Silly me I had a deadlock between client/server because of a write in the reader thread! 傻傻的我在客户端/服务器之间因为读写器线程中的写入而陷入僵局! :) Thanks :) 谢谢

Yes, it seems use Threads each for sending and receiving on both sides. 是的,似乎每个都使用Threads进行双方发送和接收。 So one socket connection can do that. 所以一个套接字连接可以做到这一点

TCP连接是一个全双工字节流 ,所以是的,您可以同时读取和写入同一个套接字,但您当然不必使用线程进行双向通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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