Hi Frendz,
I want to read data from servers port. I checked the port manually with TCP IP listener application. Its working fine and i can receive data. Now i need to develop this function in PHP. For that i just connect the server with the port and ip using the following code

<?php

	$site = "192.168.1.5";
	$port = 4321;
	
	$fp = fsockopen($site,$port,$errno,$errstr,10);
	if(!$fp)
	{
		echo "Cannot connect to server";
	}
	else
	{
		echo "Connect was successful - no errors on Port ".$port." at ".$site;
		fclose($fp);
	}
?>

But it gives the error,

"Warning: fsockopen() [function.fsockopen]: unable to connect to 192.168.1.5:4321 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in D:\xampp\htdocs\portlistener\test.php on line 6
Cannot connect to server"

But connect was successful when i use the default ports like 80,85 etc.

Whats going wrong with this?

Recommended Answers

All 4 Replies

Change line 9 of the above code to:

echo "ERROR: $errno - $errstr";

...and tell me what this error message says. Hope this helps.

Change line 9 of the above code to:

echo "ERROR: $errno - $errstr";

...and tell me what this error message says. Hope this helps.

Thanks for your reply.. :)

This is the error message.

ERROR: 10060 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

It looks like the server you are attempting to connect to is local to your network. The first thing that I would look at are the routing rules in your router, making sure that your router is not blocking the port you are trying to connect to. Also, check the firewall rules of the "server" computer to make sure that the port you are trying to use is not being blocked locally.

Also, just to help wrap my head around your problem, did you write the daemon that you are trying to connect to, or are you using a pre-packaged application? If a popular application, what app are you trying to get php to connect to?

It looks like the server you are attempting to connect to is local to your network. The first thing that I would look at are the routing rules in your router, making sure that your router is not blocking the port you are trying to connect to. Also, check the firewall rules of the "server" computer to make sure that the port you are trying to use is not being blocked locally.

Also, just to help wrap my head around your problem, did you write the daemon that you are trying to connect to, or are you using a pre-packaged application? If a popular application, what app are you trying to get php to connect to?

Ok Wraithmanilian, Thanks.. I'll check my router rules.

No I dont use any pre-packaged application to get php connect to port. I just googled my need and get this code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.