The following code should return the whole message all the time but it doesn't... I keep refreshing and at some point it prints:
Connected to UWT-RTR-002
And some others as expected:
Connected to UWT-RTR-002 Wireshark full trace start/stop control program Type "help" for instructions 2024-07-08 12:08:50 command:
Then I tried to pass the command "help" but I get nothing... It works when I use telnet on Windows Command Prompt.
UPDATE: while
is taking too long, it doesn't display any error.
$address = '10.0.0.200';
$port = 41200;
$sock = stream_socket_client("tcp://".$address.":".$port, $errno, $errstr);
fwrite($sock, "help\n");
while ($data = fread($sock, 8192)){
echo $data."<br>";
}
fclose($sock);
Trying to read and send commands to a TCP
fread()
can return less than you asked for, and it won't necessarily match a message that was written.fread()
in a loop until you get the entire message.