Communication between Java server and Android client

I've built a java server application and tried to get my Android application to communicate with it After reading Android client server communication, I tried the socket example But I encountered a problem, because on the server side, I can return my object array, but on the client side, I can't retrieve it because the buffereader only accepts a string

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;

Customer code

BufferedReader stdIn = new BufferedReader(new InputStreamReader(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 its appearance, I can't pass an object through this socket method Can JSON do what I need? I just don't want to spend another day writing something that doesn't work for me All I want to do is have a database that my server can access. The server reads the database and returns table data in the form of my object

Solution

On the client side, you read from standard input instead of socket But you should read from the socket:

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>