简体   繁体   English

仅通过一个客户端通过ObjectOutputStream发送对象

[英]send an object through ObjectOutputStream only one client

Suppose we have one server and two or more clients connected to it. 假设我们有一台服务器和两个或多个客户端相连。 The server wants to send through ObjectOutputStream an object so use it and open the server stream output using the method getOutputStream() . 服务器希望通过ObjectOutputStream发送一个对象,因此可以使用它并使用方法getOutputStream()打开服务器流输出。 The server wants to send this file only to one determinate client that have one field setted in a certain way. 服务器只希望将此文件发送给以某种方式设置了一个字段的一个确定的客户端。 the server maintains in a list the object client with all its field. 服务器在列表中维护对象客户端及其所有字段。 The server wants to send an object only to a client who has a field setted in a certain way.So the server iterates the list and after find that client send to it the object.but how can determinate into the net which is the client? 服务器只想将对象发送给具有以某种方式设置了字段的客户端,因此服务器对列表进行迭代,然后找到该客户端向其发送对象,但是如何确定进入客户端的网络呢?

让每个客户端在其更改时将其状态发送到服务器,或者将对象发送给所有客户端,如果它们的状态为false,则让他们忽略该消息。

If you really want to do this, you will need multiple connections and/or multiple round-trips. 如果确实要执行此操作,则将需要多个连接和/或多个往返。 Either the clients have to actively sent their status to the server, or the server has to ask them. 客户端要么必须主动将其状态发送到服务器,要么服务器必须询问他们。 Or, thirdly, the server could send them all the same message, but with a flag included that means 'only pay attention if you are 'free'.' 或者,第三,服务器可以向他们发送相同的消息,但其中包含一个标志,表示“仅在您有空时注意”。

Really, you'd be better off learning to use a message queue system. 确实,您最好学习使用消息队列系统。 You could use, for example, Apache ActiveMQ, and you could use Spring/JMS or Apache CXF Soap over JMS. 例如,您可以使用Apache ActiveMQ,也可以在JMS上使用Spring / JMS或Apache CXF Soap。

暂无
暂无

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

相关问题 使用 ObjectOutputStream 发送 RSA Object - Send RSA Object with ObjectOutputStream 无法通过java ObjectOutputStream发送对象 - Cannot send objects through java ObjectOutputStream ObjectInputStream / ObjectOutputStream | 接收和发送大量对象的客户端(Java) - ObjectInputStream / ObjectOutputStream | client that receive and send a lot of objects (Java) objectOutputStream 的 readObject() 方法没有接收到写入到 Client 的 inputStream 上的 object? - The readObject() Method of objectOutputStream is not receiving the object written on the inputStream to the Client? 发送更改的hashmap,但使用ObjectOutputStream和ObjectInputStream获取相同的hashmap - send changed hashmap but get the same one using ObjectOutputStream and ObjectInputStream 为什么不能用Java发送带有ObjectOutputStream的可序列化对象? - Why can't I send Serializable Object with ObjectOutputStream in Java? 从服务器向客户端发送映射对象,ObjectOutputStream错误 - Sending Map Object to Client from Server, ObjectOutputStream Error 等价于ObjectOutputStream,不仅保存其状态,还保存整个对象? - Equivalent of ObjectOutputStream, saving not only its state but the whole object? Java,在ObjectOutputStream上调用readObject()时,它仅返回一个值 - Java, when calling readObject() on an ObjectOutputStream it is only returning one value ObjectOutputStream, readObject 只从序列化文件中读取第一个对象 - ObjectOutputStream, readObject only reads first object from serialized file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM