How to create socket connection with php?

PHP Sockets on XAMPP Server problems?

  • here is my code: <?php $PORT = 9001; //the port on which we are connecting to the "remote" machine $HOST = 'localhost'; //the ip of the remote machine (in this case it's the same machine) $sock = socket_create(AF_INET, SOCK_STREAM, 0) //Creating a TCP socket or die("error: could not create socket\n"); $succ = socket_connect($sock, $HOST, $PORT) //Connecting to to server using that socket or die("error: could not connect to host\n"); $text = "Hello, Java!"; //the text we want to send to the server socket_write($sock, $text."\n", strlen($text) + 1) //Writing the text to the socket or die("error: failed to write to socket\n"); $reply = socket_read($sock, 10000, PHP_NORMAL_READ) //Reading the reply from socket or die("error: failed to read from socket\n"); echo $reply; ?> and i always get an error message and never able to successfully establish the socket connection Warning: socket_connect() [function.socket-connect]: unable to connect [0]: No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\socket\index.php on line 8 error: could not connect to host any help will do. thanks in advance.

  • Answer:

    is something running on Port 9001 on the host that can accept the socket? XAMPP default installation opens up 80 and 443 for accepting traffic, in order for it to accept traffic on 9001 you would have to modify the port in the httpd.conf in /opt/lampp/etc/ or httpd-ssl.conf in /opt/lampp/etc/extra You can create another config in $XAMPPROOT/etc/extra and use the $include in $XAMPPROOT/etc/httpd.conf that includes the directive to use port 9001. The issue is with the web server..

jackerx_... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.