kryonet缓冲区溢出异常

1cklez4t  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(315)

我试图发送一个使用kryonet库位图,我不断得到这个错误

com.esotericsoftware.kryo.KryoException: Buffer overflow. Available: 0, required: 1000000
Serialization trace:
mBuffer (android.graphics.Bitmap)
at com.esotericsoftware.kryo.io.ByteBufferOutput.require(ByteBufferOutput.java:189)
at com.esotericsoftware.kryo.io.ByteBufferOutput.writeBytes(ByteBufferOutput.java:283)
at com.esotericsoftware.kryo.io.ByteBufferOutput.writeBytes(ByteBufferOutput.java:269)
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ByteArraySerializer.write(DefaultArraySerializers.java:36)
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ByteArraySerializer.write(DefaultArraySerializers.java:25)
at com.esotericsoftware.kryo.Kryo.writeObjectOrNull(Kryo.java:577)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:68)
at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:495)
at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:599)
at com.esotericsoftware.kryonet.Kr

这是我在服务器和客户端上使用的代码

serverKryo = new Server();
                    serverKryo.start();
                    serverKryo.addListener(listener);
                    try {
                        serverKryo.bind(5050, 5060);
                        Kryo kryo = serverKryo.getKryo();
                        kryo.register(Bitmap.class);
                        kryo.register(byte[].class);
                        kryo.register(String.class);
                  } catch (IOException e) {
            e.printStackTrace();
                      }

                }

客户代码:

Thread kryoThread =    new Thread(new Runnable() {
            @Override
            public void run() {
                Client client = new Client(1000000,1000000);
                client.start();
                client.addListener(new Listener() {
                    @Override
                    public void connected(Connection connection) {
                        super.connected(connection);
                        Kryo kryo = client.getKryo();
                        kryo.register(Bitmap.class);
                        kryo.register(byte[].class);
                        kryo.register(String.class);
                        client.sendTCP(bitmap);
                    }

                    @Override
                    public void disconnected(Connection connection) {
                        super.disconnected(connection);
                    }

                    @Override
                    public void received(Connection connection, Object object) {
                            super.received(connection,object);
                        if (object instanceof  String){
                            String result = (String) object;
                            XposedBridge.log(""+result);
                        }
                    }
                });

                try {
                    client.connect(5000, "192.168.1.15" , 5050, 5060);

                } catch (IOException e) {
                    XposedBridge.log("problem in connect" );
                }

            }
        });

我尝试过以下方法1-我尝试过用构造函数增加buffersize 2-阻止执行,直到buffersize i大于所需的buffersize(这是个坏主意,它是一个无限循环)3-使用不同的端口4-在listener.connected函数中使用sendtcp

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题