1

I have ReactPHP socket server that communicate with ReactPHP clients, but I need the same with android client. How can I do that, I have some client android app but It won't connect. Can some help with some sample code, or some explanation. I am new in java and android.

Socket Server - ReactPHP

<?php
require_once __DIR__ . '/../../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server('127.0.0.1:3005', $loop);

$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
    $connection->write("Hello Vale " . $connection->getRemoteAddress() . "!\n");
    $connection->write("Welcome to this amazing server!\n");
    $connection->write("Here's a tip: don't say anything.\n");



    $connection->on('data', function ($data) use ($connection) {

        $connection->write("test", $data);
    });

});
$loop->run();

Client - ReactPHP

<?php
require_once __DIR__ . '/../../../../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$connector = new React\Socket\Connector($loop);

$connector->connect('127.0.0.1:3005')->then(function (React\Socket\ConnectionInterface $connection) use ($loop) {
    $connection->pipe(new React\Stream\WritableResourceStream(STDOUT, $loop));
    $connection->write("Hello World!\n");
});

$loop->run();

This communication works great, I need that also with android client. :)

Andry Jhonas
  • 379
  • 2
  • 13

1 Answers1

0

I recommend this library Android Socket.io client

carrasc0
  • 358
  • 2
  • 9