Note that there are some explanatory texts on larger screens.

plurals
  1. POPush message in Android
    text
    copied!<p>I have managed the get the auth Token from google and now I am trying to push the message to my android device. </p> <pre><code>//code to fetch auth Token &lt;?php $url = "https://www.google.com/accounts/ClientLogin"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); echo $url; $post_fields = "accountType=" . urlencode('HOSTED_OR_GOOGLE'). "&amp;Email=" . urlencode('mail@gmail.com'). "&amp;Passwd=" . urlencode('xxx'). "&amp;service=" . urlencode('ac2dm'); echo $post_fields; echo "&lt;br/&gt;"; $data = array('accountType' =&gt; 'GOOGLE', 'Email' =&gt; 'mail@gmail.com', 'Passwd' =&gt; 'xxx', 'source'=&gt;'PHI-cUrl-Example', 'service'=&gt;'ac2dm'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLINFO_HEADER_OUT, true); // for debugging the request var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT)); //for debugging the request $response = curl_exec($ch); var_dump($response); curl_close($ch); echo "&lt;br/&gt;&lt;br/&gt;"; ?&gt; </code></pre> <p>I get the AuthToken from google. Now I need to send my message to android device This is the php code for that...</p> <p>(second.php)</p> <pre><code>&lt;?php $wannasay = array ( "registration_id" =&gt; "APA91bH9SYn9Iru4Ddr87neqEh3OWaUhT8k_UUpxUZj7ORMLwFCiZ3qKm1yKWGFro47DNsk6CynvureInynXFqs1zEZ9xUwUlw", "collapse_key" =&gt; "abcdef" ); $dataels = array(); foreach (array_keys($wannasay) as $thiskey) { array_push($dataels,urlencode($thiskey) ."=". urlencode($wannasay[$thiskey])); } $data = implode("&amp;",$dataels); // work out the request //auth token below is the one i got from above script $authToken="DQAAAK0AAAABGiOYfUQfp_ZiDyZqErKOacSmgZCFvnogDUaVzSX9a6qh079XJblM63Z12JwOdRv8gDNCqLj80olSbFeqZFJpqXQDvmmW_PcyHUZPyDZIpZ0G0FRkV_sgqy06YM7r5zUnAggHA8hlmVM3AQBYNGcP_A2Ddq_pjm6cqaQBQH_dFaJgK6UfxNaNDK2jl78VWSU-ZMb-Q2zU1xMLbwYcWXuYIRqRxSlEN68N2M2u4Ub_AA"; $header = "POST http://android.apis.google.com/c2dm/send HTTP/1.1\n" . "Host: yourhost\n" . "Content-Type: application/x-www-form-urlencoded\n" . "Authorization: GoogleLogin auth=" . $authToken . "\n" . "Content-Length: " . strlen($data) . "\n\n" . $data . "\n"; // establish the connection and send the request $s = socket_create(AF_INET, SOCK_DGRAM, 0);//AF_INET ipv4 internet based protocol $z = socket_connect($s, gethostbyname("yourhost"), 80); socket_write ($s, $header, strlen($header)); $header = ""; while (true) { if (strlen($c = socket_read($s, 1))) { //this is line 20 $header .= $c; } } socket_close($s); print nl2br(htmlspecialchars($header)); ?&gt; </code></pre> <p>I am running both the code from localhost. I am having socket problem here I think. Either the page keeps loading forever or I gives me fatal error : maximum time exceeded 60 seconds at line 20 or so.</p> <p>When I try the code at server I get the error as</p> <pre><code>Warning: socket_read() [function.socket-read]: unable to read from socket [111]: Connection refused in second.php on line 20 </code></pre> <p>I dont know what is wrong here. Can someone tell me why am I getting this error. I have no idea how the socket thing works on Android as well. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload