如何在客户端和服务器之间建立多个IO流? [英] How does one establish multiple IO streams between a client and server?

查看:288
本文介绍了如何在客户端和服务器之间建立多个IO流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java创建一个客户端/服务器对,目前只支持通过PrintWriters和BufferedReaders围绕服务器和客户端的IO流进行隔行扫描文本通信。

I'm creating a client/server pair in Java that, for now, only supports interlaced text communication via PrintWriters and BufferedReaders wrapped around both server and client's IO streams.

我想实现一个函数,它使用Image [Input / Output] Stream以一定的间隔从服务器向客户端发送BufferedImage。

I would like to implement a function that uses Image[Input/Output]Stream to send a BufferedImage from the server to the client at a set interval.

问题是我希望在单独的线程中发送/接收BufferedImages,以便客户端/服务器仍然可以发送/接收文本命令。

The problem is that I want the BufferedImages to be sent/received in separate threads so that the client/server can still send/receive text commands.

我可以创建多个流或套接字?如果是这样,这是最好的方法吗?

Can I create multiple streams or sockets? If so, is that the best way?

推荐答案

使用单个套接字实现此目的的一种方法是将各个流复用到单个字节流连接到套接字,这是一个很好的实现 BEEP

One way to accomplish this with a single socket is multiplexing the individual streams over a single bytestream connected to the socket, a good implementation of this is BEEP.

这篇关于如何在客户端和服务器之间建立多个IO流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆