vivendi Posted April 12, 2007 Share Posted April 12, 2007 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 More sharing options...
boo_lolly Posted April 12, 2007 Share Posted April 12, 2007 replace this: switch(socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5)) with this: switch(socket_select(array($sock), array($sock), array($sock), 5)) Link to comment https://forums.phpfreaks.com/topic/46761-php-socket-problem/#findComment-227882 Share on other sites More sharing options...
vivendi Posted April 12, 2007 Author Share Posted April 12, 2007 Then i get the following error: Fatal error: Only variables can be passed by reference in C:\Program Files\Apache Group\Apache2\htdocs\remote\index.php on line 6 Link to comment https://forums.phpfreaks.com/topic/46761-php-socket-problem/#findComment-227898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.