简体   繁体   English

如何在PHP中使用'Curl'将数据发送到android

[英]How to use 'Curl' in php to send data to android

I have a listener in an android application to detect messages sent by the server php 我在android应用程序中有一个侦听器,以检测服务器php发送的消息

 public class Threa implements Runnable

{
   public static final String SERVERIP = "192.168.1.4";
    public static final int SERVERPORT =6060 ; //4444
    public BufferedReader in;
    public int x=0;
      public void run() {

             try {

                 ServerSocket serverSocket = new ServerSocket(SERVERPORT);

                 while (true)
                     {
                     x++;

                      Socket client = serverSocket.accept();
                     try {

                  in = new BufferedReader(new InputStreamReader(client.getInputStream()));

                          String str = in.readLine();

                        } catch(Exception e) {


                        } finally {
                            client.close();

                                }
                 }

             } catch (Exception e) {

                     }
        }

    }

I found this code on the Internet 我在互联网上找到了此代码

function get_url($url) 
    {
        $ch = curl_init();

        if($ch === false)
        {
            die('Failed to create curl object');
        }

        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }

    echo get_url('http://www.apple.com/');

using cURL in php to send the message is correct, if not what is the solution to solve this problem, please give me an idea 在PHP中使用cURL发送消息是正确的,如果不是解决该问题的解决方案,请给我一个想法

curl is good to communicate using protocols such as http/ftp etc.. curl非常适合使用http / ftp等协议进行通信。

If you want to send random data (ie: using your very own protocol), then you should use php sockets they are made for that : http://php.net/manual/fr/book.sockets.php 如果您想发送随机数据(即:使用自己的协议),则应使用专用于它们的php套接字: http : //php.net/manual/fr/book.sockets.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM