Member Avatar

I try to send a string of numbers (It has to be string) from one pc to the other pc throught tcp and com (serial). I use xampp as my server.
I always get the same errors:
'Warning: fsockopen() [function.fsockopen]: unable to connect to (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...'
'Unable to bind ...'

I use this code to sent:

$fp = fsockopen($host, $port, $errno, $errstr, 30);
//$host, $port -> received from the page. host: port: tried many, all failed
	if (!$fp){
      echo "$errstr ($errno)<br />\n";
		fwrite($fp, $out);
		echo "success";
to receive I tried to king: 1)
	$fp = fsockopen("", "12123", $errno, $errstr, 30);
	if (!$fp) {
		echo "$errstr ($errno)<br />\n";
	} else {
		$stng = fread($fp, 10);
echo "string: ".$stng; //just to display the string and make sure it`s working.
or (it was taken for example and mudified)
$host = ""; / set the variables
$port = 1235;

set_time_limit(0); // don't timeout!

$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // create socket

$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // bind socket to port

$result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // start listening for connections

// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");

// read client input
$input = socket_read($spawn, 1024) or die("Could not read input\n");

$input = trim($input); // clean up input string
echo "input: ".$input;

socket_close($spawn);// close sockets

the port itself is not important, I tried many and the same errors.

Help anyone!

the port itself is not important, I tried many and the same errors.

The port itself is important. The receiving computer must be listening on the port you're trying to send.