开发者

Communication between java server and android client

I have built a java server app and am trying to get my android app to communicate with it. After reading Android Client Server communication I tried the socket example. However I have run into a wall because on the server side I can return an array of my object but on the client side I'm not able to retrieve it since buffereader takes a string only Server code

public List<Person> processInput(String theInput) {
    String peopleOutput = null;
        List<Person> people = new ArrayList<Person>();



    if (state == WAITING) {
               SqliteDBhelper db = new SqliteDBhelper();
                people = db.getPeople();
return people;

Client code

BufferedReader stdIn = new BufferedReader(new InputStreamRea开发者_开发百科der(System.in));
List<Person> fromServer;
String fromUser;

while ((fromServer = in.readLine()) != null) {
  List<Person> people = new ArrayList<Person>();
  Person person = new Person();
  people = fromServer;

So from the looks of it I cannot pass an object via this socket method. Will the json do what I need? I just dont want to spend another day coding somthing that won't work for me. All I'm trying to do is have a db that my server has access to, the server reads the db and returns the table data in the form of my objects.


On the client your reading not from the socket but from the standard input. But you should read from the socket instead:

http://download.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜