Jump to content

php socket problem


vivendi

Recommended Posts

Hey, im trying to use the socket function with php. I want to connect to another listening host on port 7070 (which is running local too).

I have the following php code, but i get an error when i try it. It also says that its connected, but thats not possible because the server that listens for the incoming connections isn't running yet.

 

Here's the code that i have and the error below that.

<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
//socket_set_nonblock($sock);
socket_connect($sock,"127.0.0.1", 7070);
socket_set_block($sock);
switch(socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5))
{
        case 2:
                echo "[-] Connection Refused\n";
                break;
        case 1:
                echo "[+] Connected\n";
                break;
        case 0:
                echo "[-] Timeout\n";
                break;
}
?>

 

Warning: socket_connect() [function.socket-connect]: unable to connect [0]: No connection could be made because the target machine actively refused it. in C:\Program Files\Apache Group\Apache2\htdocs\_prvt_projects\remoteMP3\index.php on line 4

[+] Connected

Link to comment
https://forums.phpfreaks.com/topic/46761-php-socket-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.