A service running in the Server is listening to port 2978 on 1xx.xxx.xx.xx for incoming connections! My PHP code receives URL data through get method. A tcp connection has to be established with the 'service' on that port and the data received from the URL should be sent to the service. The service responds with another data to the same port. this data should be obtained by the code and be saved in a file.

I've written the code. But its showing error! help me pls!!

//fsockopen("tcp://1xx.xxx.xx.xx",2978 , $errno, $errstr, 30); 
echo urldecode($CONTENT);
$Handle = fopen("/xxx/xxx/OldData.txt", "a");
fwrite($Handle, $CONTENT);
// set IP and Port number
$host = "1xx.xxx.xx.xx";
$port = 2978;
set_time_limit(0);                                                                           // No timeout
$socket = socket_create(AF_INET, SOCK_STREAM, tcp) or die("Could not create socket\n");  // creating a socket
$result = socket_connect($socket, $host, $post) or die ("Could not connect to socket\n");    // connecting socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");           // binding socket to port
$result = socket_listen($socket, 1) or die("Could not set up socket listener\n");            // starting to listening for connections
$anothersocket = socket_accept($socket) or die("Could not accept incoming connection\n");    // accept incoming connections and create another socket to handle communication
socket_write($anothersocket, $CONTENT, strlen($CONTENT)) or die ("Could not write output\n");// writing content to port (Input to CS)
$output = socket_read($anothersocket, 1024) or die ("Could not read output from CS\n");      // Getting the output from CS
$Handle1 =fopen("/xxx/xxx/NewData.txt", "a");
fwrite($Handle1, $output);
socket_close($anothersocket);                                                               // close sockets

Fatal error: Call to undefined function socket_create() in /opt/x_apache/s1051713/cgi_bin/project/Server.php on line 14

6 Years
Discussion Span
Last Post by edwinhermann
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.