So, i have mIRC making a listen (bear with me on this one) on port 1235 and i tried to make a php script to connect to such port on my localhost server.
My localhost is a clean Apache+PHP with mIRC being run on another computer (inside lan).
The script works half-right as: 1) it connects to the 1235 port 2) it sends the $i 2.1) but on the other side no msg is recieved (aka I get a sock read event but no text pops up) 3) it reads all the incoming messages correclty 4) it closes when 'end' is the message drumroll 5) it only works IF the while function isn't present. 5.1) aka Inifi-loading. it only shows echo when socket is closed via 'end'
here is the code, which is a simple example i found on php.net, thanks in advance :)
<?php
//The Client
error_reporting(E_ALL);
$address = "192.168.1.101";
$port = 1235;
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "socket successfully created.\n";
}
echo "Attempting to connect to '$address' on port '$port'...";
$result = socket_connect($socket, $address, $port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "successfully connected to $address.\n<br>";
}
$allow = true;
$i = 0;
while ($allow == true)
{
$i++;
echo "Sending $i to server.\n<br>";
socket_write($socket, $i, strlen($i));
$input = socket_read($socket, 2048);
if ($input == 'end') {
$allow = false;
}
echo "Response from server is: $input\n";
sleep(5);
}
echo "Closing socket...";
socket_close($socket);
?>
this is what i get in browser, after saying 'end'
socket successfully created. Attempting to connect to '192.168.1.101' on port '1235'...successfully connected to 192.168.1.101. Sending 1 to server. Response from server is: ok Response from server is: end
this is in mIRC:
test: 89.152.172.21 is in! read close Blockquote
if i had left it working for an hour, multiply "read" for 60 and "sending N+1 to server" but this only shows up AFTER sock close (or by stoping the while)
echos
it's spitting out when you run that? Could be helpful in debugging it.echos
spat out :)