开发者

How to send an ArrayList from a client to a server

开发者 https://www.devze.com 2023-03-15 20:45 出处:网络
The object in the ArrayList contains different primitive types and a strange type. Like object = (int, float, float[], PApplet)

The object in the ArrayList contains different primitive types and a strange type. Like

object = (int, float, float[], PApplet)

PApplet is descended from Applet, actually I do not what is it.

How to send this kind of ArrayList from a client to a server?

Than开发者_Go百科ks in advance!


Ok so i dont know if you are familiar with the concept of Serialization but heres some code that i think will help you out,

public class Packet implements Serializable
{
    public Packet(int[] numArray, char[] letterArray, String wordArray)
    {
        this.numArray = numArray;
        this.letterArray = letterArray;
        this.wordArray = wordArray;
    }

    public int[] numArray;
    public char[] letterArray;
    public Stirng[] wordArray;
}

so now heres the other half, you have to use an objectStream, the code is somthing like:

try
{
    ObjectOutputStream writer = new ObjectOutputStream(socket.getOutputStream());
    writer.writeObject(new Packet(...data));
}catch(Exception e){e.printStackTrace();}

and then of course the server would have an ObjectInputStream and do the opposite, if you need anymore help just e-mail me and ill help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消