zhouaini528 / binance-php

Binance API Like the official document interface, Support for arbitrary extension.
MIT License
107 stars 43 forks source link

stream_socket_client(): Unable to connect to tcp://0.0.0.0:2208 #48

Open younisch96 opened 1 year ago

younisch96 commented 1 year ago

I am getting the following error

(1)Warning: stream_socket_client(): Unable to connect to tcp://0.0.0.0:2208 (The requested address is not valid in its context) in \lin_binance\vendor\workerman\globaldata\src\Client.php on line 66

(2)Fatal error: Uncaught Exception: The requested address is not valid in its context in\vendor\workerman\globaldata\src\Client.php:69 Stack trace: #0

feels like it is unable to connect to binance server

zhouaini528 commented 1 year ago

You try to use the test example websocket, first open the server and then the client.And the server must be able to access the binance network normally.

younisch96 commented 1 year ago

still same error after opening server first and then client. i have made two php files socketserver.php and socketclient.php

(1)in socketserver.php the code is following $binance=new BinanceWebSocket(); $binance->config([ 'baseurl'=>'ws://fstream.binance.com',//usdt future ]); $binance->start(); it gives the output as->Only run in command line mode

(2) in socketsserver.php file code is following. $action=intval($_GET['action'] ?? 1);//http pattern if(empty($action)) $action=intval($argv[1]);//cli pattern switch ($action){...} but gives the same error as Warning: stream_socket_client(): Unable to connect to tcp://0.0.0.0:2210 (The requested address is not valid in its context) in \lin_binance\vendor\workerman\globaldata\src\Client.php on line 66

Fatal error: Uncaught Exception: The requested address is not valid in its context in

NOTE: switch action one ,because I am subscribing.

zhouaini528 commented 1 year ago

I didn't find this problem in my test.

1:run server_usdt_future.php in cli mode 2023-03-14 14-27-54屏幕截图

2:run client_usdt_future.php 3 and 10004 in cli mode, 3 is subscribing, 10004 is the subscription result. 2023-03-14 14-28-50屏幕截图

younisch96 commented 1 year ago

How can i echo this result data to the browser instead of CLI?I also want to save the data in my DB so how can I do in PHP?

zhouaini528 commented 1 year ago

You can run the client directly in the browser usdt_ future.php.There are many ways for PHP to save databases online, but I suggest storing them in Redis first.

younisch96 commented 1 year ago

Can not I get the results directly in php without running this CLI thing?

zhouaini528 commented 1 year ago

server_usdt_future.php must be run in CLI mode, client_usdt_future.php has no restrictions.

younisch96 commented 1 year ago

same error in CLI mood also lin_cli_error

younisch96 commented 1 year ago

any response plz?

zhouaini528 commented 1 year ago

same error in CLI mood also lin_cli_error

must be in Linux system.

younisch96 commented 1 year ago

thank u ,in linux it works perfectly.by using client_usdt_future.php,it outputs the following ticker info {"btcusdt@miniTicker":{"stream":"btcusdt@miniTicker","data":{"e":"24hrMiniTicker","E":1679910170338,"s":"BTCUSDT","c":"27903.60","o":"27658.10","h":"28186.90","l":"27590.60","v":"413055.926","q":"11507899578.52"}}}

but it only returns one time. when i run the while loop. my browser stucks,i am running the following code.

$data=$binance->getSubscribes(); print_r(json_encode($data)); while(1){ pcntl_alarm(0); sleep(1); $data=$binance->getSubscribes(); print_r(json_encode($data)); }

zhouaini528 commented 1 year ago

If you want the browser to continuously output results, you can use javascript ajax technology to implement and access the client usdt future.php。 You can also output results in CLI mode without getting stuck.

younisch96 commented 1 year ago

thank u. then what is the purpose of given while loop?

zhouaini528 commented 1 year ago

thank u. then what is the purpose of given while loop?

You need to understand what a daemon.The purpose of the loop is to facilitate the output of the displayed data, all of which are in the linux system cli mode. You can try it on the command line cli and you will know.