如何在Android中使用TCP / IP向服务器发送经度和纬度

时间:2015-03-24 08:24:20

标签: java android sockets tcp

这是我的asyntask类,我尝试连接到服务器并将纬度和经度发送给它。

public class MyClientTask extends AsyncTask<Void, Void, Void> {
   MyClientTask() {}

    @Override
    protected Void doInBackground(Void... arg0) {
        Socket socket = null;
        try {
             socket = new Socket("107.170.21.173", 8000);
             OutputStream out = socket.getOutputStream();
             out.write("latitute".getBytes());// sending the lat to server
             out.write("longitute".getBytes()); // sending the long to server
             InputStream inputStream = socket.getInputStream();
             int output=inputStream.read();
        }
        catch (UnknownHostException e)    
             e.printStackTrace();
        response = "UnknownHostException: " + e.toString();
}

但是我无法读取输入流即服务器的响应。我读出了TCP / IP连接,但无法在我的代码中实现它。

0 个答案:

没有答案