如何在Android手机中接收GPRS数据包?

时间:2012-04-16 04:22:16

标签: android android-intent gsm gprs

我需要通过我的Android手机接收通过GPRS从GSM调制解调器发送的数据包... 任何人都可以帮我如何发送和接收.. 必须使用什么协议?

1 个答案:

答案 0 :(得分:2)

在服务器启动时创建一个线程并执行以下操作

ServerSocket serverSocket = new ServerSocket(8000); //8000 - port number
Socket client = serverSocket.accept();  // thread will wait here till a client connects

BufferedReader inFromClient = new BufferedReader(
                        new InputStreamReader(client.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(
                        client.getOutputStream());
while ((inputLine = inFromClient.readLine()) != null) {   
                    System.out.println("Server: " + inputLine);

                    if(inputLine.equals("END"))
                    {
                        outToClient.writeBytes("END\n");
                    }
                    else
                    {
                        outToClient.writeBytes("Received\n");
                    }
                }
                inFromClient.close();
                outToClient.close();

您需要处理的TCP连接