0

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?

jcsanyi
  • 8,133
  • 2
  • 29
  • 52
boea pj
  • 9
  • 6

1 Answers1

2

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.

Mikko Rantalainen
  • 14,132
  • 10
  • 74
  • 112
  • Obviously, adding `@` will not make the connection successful but only allow your own code to handle the failure. The failure in original question is probably caused by too eager firewall settings. – Mikko Rantalainen May 01 '21 at 10:36