socket发送当前位置

时间:2011-05-24 18:46:04

标签: android

现在我在我的android项目中创建一个套接字,以便能够将我的lat和我当前位置的长度发送到我的python服务器,我的android代码正在使用三星迷你galaxy。这是我的代码

public void connect(View view){
    try{
        clientSocket= new Socket("192.168.1.2",54635); 
        Text.append( "\n created a socket");
        outToServer = new DataOutputStream(clientSocket.getOutputStream());
        Text.append( "\n created a datastream");
        inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        Text.append( "\n created a bufferReader");

    }catch(Exception e){
        System.out.println("Error");
    }
    } 
        public void onLocationChanged(Location loc)

    {

        GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
                (int) (loc.getLongitude() * 1E6));
        String cmd=("My current location is: " +

        "Latitud =" + loc.getLatitude()*1E11+ 

        "Longitud =" +loc.getLongitude()*1E11);
        try {
              Connect=(Button)findViewById(R.id.connect);
           InetSocketAddress address = new InetSocketAddress("192.168.1.2",54631);
            DatagramPacket request = new DatagramPacket(cmd.getBytes(), cmd.length(), address);
            DatagramSocket socket = new DatagramSocket();
            socket.send(request);
        } catch (SocketException e) {

      System.out.print("SSSS");
            }
         catch (IOException e) {

           System.out.print("SSS");
            }
        }

问题是我希望连接消息能够发送lat和long,因为InetSocketAddress力关闭了。那么请问什么可能是一个解决方案

0 个答案:

没有答案