Send to multiple clients without multiple kryo serializations

142 views
Skip to first unread message

hwee

unread,
May 8, 2011, 10:06:53 PM5/8/11
to kryonet-users
Hi Nate,

I know of the sendToAllTCP/UDP method in the Server class, however, I
am only trying to send to a subset of the connected clients.
Would it be possible to create another method or overload an existing
one to accept an already kryo serialized object in a byte[] or
ByteBuffer so that the send method does not call kryo serialize more
than once?

Thanks!

Furyhunter

unread,
Jun 18, 2011, 3:31:06 AM6/18/11
to kryone...@googlegroups.com
Hello,

I need this functionality as well, although it is not completely imperative that it exists. It would be an improvement in performance to avoid running so many calls to serializers, especially if a custom serializer hasn't been written for the object in question. For example, I'm assuming the use would be to broadcast a command to only a few connections that are within a certain game zone.

I don't think it would be safe to allow raw byte arrays or buffers to be sent through Kryo, as the other end point may not be able to deserialize the object properly should the array be modified. Perhaps an immutable SerializedObject or similar would be useful in this case?

Nate

unread,
Jun 30, 2011, 5:21:48 PM6/30/11
to kryone...@googlegroups.com
I've been working on the next generation of Kryo, so I'd like to hold off on a change like this for KryoNet. When it is implemented though, the serialized bytes will be copied to a data structure that can be used to send the same bytes again.

I'm busy relocating over the next few weeks, so it will be a little while, sorry!

-Nate



--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users

Furyhunter

unread,
Jun 30, 2011, 5:45:53 PM6/30/11
to kryone...@googlegroups.com
Awesome! I'll contribute where I can when the time comes, then.

lifei...@gmail.com

unread,
Aug 17, 2018, 9:24:50 PM8/17/18
to kryonet-users
I am just a Kryonet user.
The direction of communication from client to server, server to client etc is irrelevant. This problem is that you can not input raw data into sendTCP. It will cause Kryo's class filtering to be ignored. Classes can be registered with Kryo # register (). That limits the classes that can communicate. In Kryonet 's API design, there is a trade - off between security and performance.
The solution is probably something like this. A class called KryonetMessage is needed for Kryonet. KryonetMessage has Kryo inside, receives the Object class and serializes it. Class filtering is done in KryonetMessage setup. Methods like sendTCP (Object o) should be deprecated. There should be only methods like sendTCP (KryonetMessage m). KryonetMessage m is used in many sendTCP (). This solution combines security and performance. However, the API gets a bit dirty. I think that it is an acceptable range.

Nate

unread,
Aug 21, 2018, 9:00:58 AM8/21/18
to kryone...@googlegroups.com
It's not super clear what your needs are or how they are related to the 7 year old thread you posted in.

You can provide your own KryoNet serialization to use Kryo for your KryonetMessage objects and something else for other objects. Otherwise, to just send bytes, just send an object whose class has a byte[] field.

-Nate


--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users
---
You received this message because you are subscribed to the Google Groups "kryonet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryonet-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lifei...@gmail.com

unread,
Aug 22, 2018, 4:37:19 PM8/22/18
to kryonet-users
I recently encountered this problem, searched and found this topic. I did not know whether to write a new topic or to write it here. However, I already finished the transition to Netty. Netty is strong against such simultaneous communication. Kryonetty may be one option.

2018年8月21日火曜日 22時00分58秒 UTC+9 Nate:
To unsubscribe from this group and stop receiving emails from it, send an email to kryonet-user...@googlegroups.com.

Johnny Longstockings

unread,
Sep 16, 2018, 12:41:26 PM9/16/18
to kryonet-users
You could write your own KryoSerialization class and override these methods.
    public synchronized void write (Connection connection, ByteBuffer buffer, Object object) {
        output
.setBuffer(buffer);
        kryo
.getContext().put("connection", connection);
        kryo
.writeClassAndObject(output, object);
        output
.flush();
   
}

   
public synchronized Object read (Connection connection, ByteBuffer buffer) {
        input
.setBuffer(buffer);
        kryo
.getContext().put("connection", connection);
       
return kryo.readClassAndObject(input);
   
}


Reply all
Reply to author
Forward
0 new messages