boea pj
boea pj

Reputation: 9

php fsockopen() cannot make connection

I have a problem about fsockopen().

when i write code from http://tokudu.com/2010/how-to-implement-push-notifications-for-android it doesn't work, and i get:

Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:port
(No connection could be made because the target machine actively refused it. )
in C:\xampp\htdocs\PhpMQTTClient-master\SAM\MQTT\sam_mqtt.php on line 641
Offline

I have try this, but it cannot solve my problem.
Can anybody help me solve this problem?

Upvotes: 0

Views: 1840

Answers (1)

Eyad AL Qhatani
Eyad AL Qhatani

Reputation: 21

This function fsockopen("www.example.com", 80) returns a stream resource if the connection is successful.

However, if the connection fails it will generate an error as you receive:

You can use @ operator to silence the error

$resource = @fsockopen("127.0.0.1","882");
// $resource will be stream resource object if call is successful
// $resource will be false if call  fails

to avoid raising and error and get false as the return value when connection fails.

Upvotes: 2

Related Questions