SportScore

PAID
Verified
By Tipsters CO | Updated 6 days ago | Sports
Popularity

9.9 / 10

Latency

55ms

Service Level

100%

Back to All Tutorials (3)

How to get live data without delay?

Many users are interested in the question of how to receive data without delay.
We suggest using the Sport/@Events by sport ID and date endpoint first, you will get a list of matches by date and sport.

Then you want to receive new data without delay?

You have 2 options.

  1. Use points Events/@Event live list or Sport/@Events live by sport ID. Call them as often as you want.
  2. Use a WebSocket no latency in real-time

A WebSocket is a persistent connection between a client and server.
WebSockets provide a bidirectional, full-duplex communications channel that operates over HTTP through a single TCP/IP socket connection.
At its core, the WebSocket protocol facilitates message passing between a client and server.

How to connect?

Server socket address:
wss://tipsscore.com:2083/app/7UXH2sNFqpVAO6FebyTKpujgfy8BUnM?protocol=7&client=js&version=5.0.3&flash=false

First message:
Submit what sport and locale you are connecting to.
Ex.:

{"event":"pusher:subscribe","data":{"channel":"en-football-list"}}
{"event":"pusher:subscribe","data":{"channel":"en-hockey-list"}}

You must maintain connections by sending this message every 15 seconds

{"event":"pusher:ping","data":{}}

As soon as the score or match details change, you will receive messages without delay
Ex.:

{"channel":"ru-football-list","event":"App\\Events\\UpdateDataLine","data":"{\"data\":[{\"sport\":\"football\",\"id\":980333,\"league_id\":null,\"challenge_id\":34942,\"time_live\":37,\"status\":\"inprogress\",\"status_loc\":\"\\u0432 \\u0438\\u0433\\u0440\\u0435\",\"home_score\":{\"current\":2,\"display\":2},\"away_score\":{\"current\":1,\"display\":1},\"winner_code\":0,\"main_odds\":[],\"first_supply\":null},{\"sport\":\"football\",\"id\":984416,\"league_id\":8978,\"challenge_id\":35140,\"time_live\":34,\"status\":\"inprogress\",\"status_loc\":\"\\u0432 \\u0438\\u0433\\u0440\\u0435\",\"home_score\":{\"current\":0,\"display\":0},\"away_score\":{\"current\":1,\"display\":1},\"winner_code\":null,\"main_odds\":[],\"first_supply\":null}]}"}
{"channel":"ru-football-list","event":"App\\Events\\UpdateDataLine","data":"{\"data\":[{\"sport\":\"football\",\"id\":985350,\"league_id\":728,\"challenge_id\":1648,\"time_live\":6,\"status\":\"inprogress\",\"status_loc\":\"\\u0432 \\u0438\\u0433\\u0440\\u0435\",\"home_score\":{\"current\":0,\"display\":0},\"away_score\":{\"current\":0,\"display\":0},\"winner_code\":0,\"main_odds\":[],\"first_supply\":null}]}"}

Implementation example

Visit Site, Open Console, WS Tab
You will see how the data is updated in real time.
https://tipsscore.com/en/tennis

PHP code:


use Illuminate\Console\Command;
use Ratchet\Client\Connector as RatchetConnector;
use Ratchet\Client\WebSocket;
use Ratchet\RFC6455\Messaging\MessageInterface;
use React\EventLoop\StreamSelectLoop;
use React\Socket\Connector as ReactConnector;
use Exception;

$loop = new StreamSelectLoop();
$reactConnector = new ReactConnector($loop, [
	'dns' => '8.8.8.8',
	'timeout' => 5,
	'tls' => array(
		'verify_peer' => false,
		'verify_peer_name' => false
	)
]);

$connector = new RatchetConnector($loop, $reactConnector);

$url = 'wss://tipsscore.com:2083/app/7UXH2sNFqpVAO6FebyTKpujgfy8BUnM?protocol=7&client=js&version=5.0.3&flash=false';

$connector($url, [], [])
	->then(function (WebSocket $conn) use ($loop) {

		$conn->on('message', function (MessageInterface $msg) use ($conn, $loop) {
			$this->info($msg);
		});

		$conn->on('close', function ($code = null, $reason = null) {
			echo "Connection closed ({$code} - {$reason})\n";
		});

		// Start CONNECT
		$conn->send('{"event":"pusher:subscribe","data":{"channel":"en-football-list"}}' . PHP_EOL);
		$conn->send('{"event":"pusher:ping","data":{}}' . PHP_EOL);

		// Ping - Pong
		$loop->addPeriodicTimer(15, function () use ($conn) {
			$conn->send('{"event":"pusher:ping","data":{}}' . PHP_EOL);
		});
		
	}, function (Exception $e) use ($loop) {
		echo "Could not connect: {$e->getCode()}\n";
		$loop->stop();
	});

$loop->run();

Rating: 4.3 - Votes: 7