In games most code is shared between server and client so normally they're
built on the same language, and even in the same framework. Sometimes you
need to share load with the client to increase the amount of players. So
I'm not too worried about inter-language interoperability.

I'm not sure having a separate connection with the player for multicast
would solve the problem, the gob encoder still needs to keep track about
the types he sent, and when multicasting the gob doesn't see the
connection, either a bytes.Buffer or MultiWriter, and it gets lost because
the underlying connections are constantly changing.

Ideally i need a protocol that doesn't need to sent the type information
before the data, having the type embedded into the data itself. gob builds
a machine of sorts and sends it over the wire if i'm not mistaken, i guess
that's where it goes downhill.

On Wed, 23 Dec 2020, 23:06 Bakul Shah, <ba...@iitbombay.org> wrote:

> I looked at your top level README.md to understand what you are doing.
> Do these players join at the same time or different times? If different
> times, that can explain corruption with MultiWriter.
>
> One suggestion is to use "bufio" to create a writer for the gob encoder
> out of a []byte buffer. Then after each encoding, grab the buffer and send
> it out to each receiver on a separate connection. This costs the encoding
> overhead just once regardless of receivers. You may have to play with this
> a bit to make sure the receiver side decoder works seamlessly even when you
> send N such byte strings. [I haven't looked at how gob is implemented so
> don't know if this is possible]
>
> I'd avoid UDP unless your app can tolerate some loss. If you need reliable
> delivery, you may as well use TCP. Also, don't expect UDP broadcast to work
> across the Internet!
>
> Probably a good idea to use JSON as others have suggested, as you can then
> interoperate with programs written in other languages. [In general external
> interfaces should be language neutral]
>
> On Dec 23, 2020, at 1:45 PM, meera <lordhowen...@gmail.com> wrote:
>
> I am trying to create a package for game servers using gob. The current
> approach is an application level multicasting over TCP, having a gob
> encoder and decoder for each player connection, and set up a goroutine to
> receive and another to dispatch for each one. The code for the dispatcher
> is here. But summarized, it simply receives data from a channel and encodes
> it.
>
> The problem is that if i want to transmit a single piece of data to all
> players, this piece of data is encoded again and again for each connection,
> doing duplicate work. With less than 100 players this is not a problem, but
> with 300+ my machine is at almost 100% usage and the profiler shows that
> most of it is spent on encoding. Here's the issue on github.
>
> I tryied using a io.MultiWriter but gob complains of duplicate type
> received, and if i try to write the raw bytes from the gob.Encoder i get
> corrupted data. An option is using UDP Broadcasting but since gob expects a
> stream, i'm affraid i will run into unexpected behavior when packets start
> to be lost and fragmented.
>
> Does gob expect a single encoder and decoder to own the stream? Not
> allowing two encoders on the server for one decoder on the client?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/0562184e-bbcc-44c9-adbf-37e8d5411c7cn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/0562184e-bbcc-44c9-adbf-37e8d5411c7cn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAE%3DAWBUYKy5uPoBseHYOAa8LyO-mfXZF-G5ExsDtZTd3NK6WRA%40mail.gmail.com.

Reply via email to