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, "helpn");
while ($data = fread($sock, 8192)){
echo $data."<br>";
}
fclose($sock);
Trying to read and send commands to a TCP
2
Answers
This is what the server-guy did and it loads fast:
Since TCP doesn’t have message boundaries, you have to define a way to tell how long the message is yourself. One option is to send the message length first, then read that many bytes in a loop.
This code will work as long as messages are less than 256 bytes long.